0
這兩個替代方法之間是否有區別......它們是否可以互換使用?自定義註釋vs使用JEE6中的@named
(A)創建自定義註釋,以便@注入可被用來代替一@PersistenceContext DAO內,如圖中的答案爲 - how-to-stack-custom-annotation-in-java-with-inject-annotation
(B)使用@Named( 「YOURNAME」)來限定生產者,如下面的代碼示例。
public class Resources {
/**
* EntityManager's persistence context is defined here so the @Inject annotation may be used in referencing classes.
*/
@Produces
@Named("MyEm")
@PersistenceContext(unitName = "jboss.managed")
private EntityManager em;
}
@Stateless
public class FiletracksentHome {
..
@Inject
@Named("MyEm")
private EntityManager entityManager;
..
}