JPA中的注入是什么
What is injection in JPA
public class SeatAllocationService implements Serializable {
@Inject
EntityManager entityManager;
//...
}
我正在阅读 Ticket-monster.2.1.6.final。这个注释让我很困惑。查找 Oracle 和 google 没有帮助:根据 oracle 文档,@inject 标识可注入的构造函数、方法和字段。然而,什么是可注入构造函数?
根据 specifications:
The @Inject annotation defined by the Dependency Injection for Java specification identifies an injected field which is initialized
by the container when the bean is instantiated, or an initializer method which is called by the container after the bean is
instantiated, with injected parameters.
@Inject 注释是 Java 依赖注入的一部分。 CDI(内容和依赖注入)已更新到 JavaEE 7,但已经是 JavaEE 6 的一部分。在此处阅读有关 CDI 的文档:
http://docs.oracle.com/javaee/6/tutorial/doc/giwhb.html
对于这个具体的例子。 EntityManager 应该用 @PersistenceContext not with @Inject. Refer to this SO 问题注释。
public class SeatAllocationService implements Serializable {
@Inject
EntityManager entityManager;
//...
}
我正在阅读 Ticket-monster.2.1.6.final。这个注释让我很困惑。查找 Oracle 和 google 没有帮助:根据 oracle 文档,@inject 标识可注入的构造函数、方法和字段。然而,什么是可注入构造函数?
根据 specifications:
The @Inject annotation defined by the Dependency Injection for Java specification identifies an injected field which is initialized by the container when the bean is instantiated, or an initializer method which is called by the container after the bean is instantiated, with injected parameters.
@Inject 注释是 Java 依赖注入的一部分。 CDI(内容和依赖注入)已更新到 JavaEE 7,但已经是 JavaEE 6 的一部分。在此处阅读有关 CDI 的文档:
http://docs.oracle.com/javaee/6/tutorial/doc/giwhb.html
对于这个具体的例子。 EntityManager 应该用 @PersistenceContext not with @Inject. Refer to this SO 问题注释。