当我尝试注入EntityManager时,它始终为null而不抛出异常。 如果persistence.xml被放置在哪里,如果它是空的或缺失,那么这并不重要;这个文件似乎完全被忽略了。 我的persistence.xml放在src / main / resources / META-INF /中。 我试着让它在Jetty中运行2天,但是没有办法。我将衷心感谢您的帮助。
我的制作人:
@Singleton
public class ApplicationResources {
@PersistenceUnit
private EntityManagerFactory emManagerFactory;
@Produces
public EntityManagerFactory produces() {
System.err.println("produces " + emManagerFactory);
return emManagerFactory;
}
}
我的DAO
@Stateless
public class AverageCountryPricesDAO {
@Inject
private EntityManagerFactory emManagerFactory;
public AverageCountryPricesDAO() {
System.err.println("construct DAO");
}
public void testit() {
System.err.println("emManagerFactory: " + emManagerFactory);
}
}
我的pom.xml
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.1.8</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version>
</dependency>
<!-- weld-servlet JAR is manually removed from WAR file -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-plus</artifactId>
<version>8.1.7.v20120910</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.7.v20120910</version>
</dependency>
</dependencies>
提前致谢, 添