Whenever I use CDI managed beans in my Enterprise Application Project, I get the CDI deployment failure:WELD-001408 exception. This is what I get:
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)
and the exception:
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)
This is the class:
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();
}
}
I inject with
@Inject
private EntityManager em;
I'm using Glassfish 4.1 and JDK build 1.8.0_25-b17
edit:
META-INF/beans.xml (EJB project):
<?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>
<?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>
– mherwig