1
每當我在我的企業應用程序項目中使用CDI託管的bean時,我得到CDI部署失敗:WELD-001408異常。這就是我得到:CDI部署失敗:使用CDI bean時的WELD-001408(Glassfish 4.1)
Injection method name must start with "set"
symbol: javax.persistence.PersistenceUnit
location: public javax.persistence.EntityManager de.syngenio.backend.beans.Resources.create(javax.persistence.EntityManagerFactory)
和異常:
Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type EntityManagerFactory with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Produces @ConversationScoped @PersistenceUnit public de.syngenio.backend.beans.Resources.create(EntityManagerFactory)
at de.syngenio.backend.beans.Resources.create(Resources.java:0)
這是類:
public class Resources {
@Produces
@ConversationScoped
@PersistenceUnit(unitName = "mongodb-pu")
public EntityManager create(EntityManagerFactory emf) {
return emf.createEntityManager();
}
public void close(@Disposes EntityManager em) {
em.close();
}
}
我
@Inject
private EntityManager em;
注入我使用Glassfish 4.1和JDK build 1.8.0_25-b17
編輯:
META-INF/beans.xml文件(EJB項目):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
META-INF/persistence.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="mongodb-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.target-database" value="org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform"/>
<property name="eclipselink.nosql.connection-spec" value="org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec"/>
<property name="eclipselink.nosql.property.mongo.port" value="27017"/>
<property name="eclipselink.nosql.property.mongo.host" value="localhost"/>
<property name="eclipselink.nosql.property.mongo.db" value="webshop"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
我認爲你在webapp/WEB-INF /文件夾中缺少beans.xml文件。 對於CDI來說,即使空如https://gist.github.com/sejersbol/845053 – rangalo 2014-11-04 19:39:10
其實它在那裏。對不起,我錯過了寫這個。我在EJB項目的META-INF /中有一個beans.xml文件。 <?xml version =「1.0」encoding =「UTF-8」?> ' –
mherwig
2014-11-04 19:43:08
您還可以在您聲明持久性單元的位置粘貼persistence.xml嗎?數據源是用gf創建的嗎?是否還有其他與db相關的異常? – rangalo 2014-11-04 19:45:13