什么是包注释的意义呢? [英] What's the point of package annotations?

查看:172
本文介绍了什么是包注释的意义呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解类注释的目的,这要归功于如何以及在哪里在Java?使用注解。什么是注解包的目的,在这个博客帖子描述 和的§7.4.1.1的Java语言规范

您为什么要与元数据包关联?你可以做什么样的事情呢?


解决方案

  1. BND工具(和Maven束-插件),使使用包注释。把 @Version 并@Export标注在package-info.java允许它产生的OSGi元数据。

  2. 的javadoc使用注解包。

  3. JAXB使用包级别的注解,例如 ,指定Java类型到XML模式类型的包全的映射。注解包也使用在JBoss中的XML绑定。

  4. Struts 2的公约插件使用<一个href=\"http://struts.apache.org/2.1.8/struts2-plugins/struts2-convention-plugin/apidocs/org/apache/struts2/convention/annotation/DefaultInterceptorRef.html\">an注释指定包中的所有操作的默认拦截器。

  5. 有一些包级别的<一个href=\"http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/annotations/package-summary.html\">Hibernate注释的。这些标注使用的例子可以在这里找到

I understand the purpose of class annotations, thanks to How and where are Annotations used in Java?. What is the purpose of package annotations, as described in this blog post and §7.4.1.1 of the Java Language Specification?

Why would you want to associate metadata with a package? What kinds of things could you do?

解决方案

  1. bnd tool (and maven-bundle-plugin) makes use of package annotations. Putting @Version and @Export annotation in package-info.java allows it to generate OSGi metadata.
  2. javadoc uses package annotations.
  3. JAXB uses package-level annotations, for example, to specify mapping of a Java type to XML Schema type package-wide. Package annotations are also used in JBoss's xml binding.
  4. Struts 2 Convention plugin uses an annotation to specify a default interceptor for all actions in a package.
  5. There are some package-level Hibernate Annotations. An example of those annotations' usage can be found here.

这篇关于什么是包注释的意义呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆