在Spring中,有两个单独的注释用于按名称执行依赖注入,javax.annotation.Resource和javax.inject.Named. documentation at Spring表示@Resource应该按名称用于注入:
If you intend to express annotation-driven injection by name,do not
primarily use @Autowired,even if is technically capable of referring
to a bean name through @Qualifier values. Instead,use the JSR-250
@Resource annotation,which is semantically defined to identify a
specific target component by its unique name,with the declared type
being irrelevant for the matching process.
上面的内容有点令人困惑,因为Spring只提倡@Resource而不是@Autowired和@Qualifer.直到later in the documentation才提及@Named.
JSR-250定义了@Resource,而JSR-330定义了@Inject和@Named.我知道它们可以很容易地在Spring中混合和匹配.使用哪个JSR?
看起来像Guice和CDI的可移植性会很好,因此使用JSR-330注释.另一方面,文档还指出Spring中使用JSR-330注释时的几个limitations.
注释注释的最佳实践(如果有)是什么?
谢谢.