java - CDI deployment failure:WELD-001408 when using CDI beans (Glassfish 4.1) -
whenever utilize cdi managed beans in enterprise application project, cdi deployment failure:weld-001408 exception. get:
injection method name must start "set" symbol: javax.persistence.persistenceunit location: public javax.persistence.entitymanager de.syngenio.backend.beans.resources.create(javax.persistence.entitymanagerfactory)
and exception:
exception during lifecycle processing org.glassfish.deployment.common.deploymentexception: cdi deployment failure:weld-001408: unsatisfied dependencies type entitymanagerfactory qualifiers @default @ injection point [backedannotatedparameter] parameter 1 of [backedannotatedmethod] @produces @conversationscoped @persistenceunit public de.syngenio.backend.beans.resources.create(entitymanagerfactory) @ de.syngenio.backend.beans.resources.create(resources.java:0)
this class:
public class resources { @produces @conversationscoped @persistenceunit(unitname = "mongodb-pu") public entitymanager create(entitymanagerfactory emf) { homecoming emf.createentitymanager(); } public void close(@disposes entitymanager em) { em.close(); } }
i inject with
@inject private entitymanager em;
i'm using glassfish 4.1 , 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>
when using entitymanagerfactory
parameter in managed methods, should ensure entitymanagerfactory
injectable too. because method "create" managed, parametervalues created in similar way @inject. don't know why entitymanagerfactory
not injectable nor if right way obtain instance of it. suggestion be: 1. obtain entitymanagerfactory
in way in create-method 2. or write producer entitymanagerfactory
creates , returns new entitymanagerfactory
.
java java-ee glassfish cdi weld
No comments:
Post a Comment