当我在此博客上工作时,遇到此错误:
[INFO ] DSRA8203I: Database product name : MySQL
[INFO ] DSRA8204I: Database product version : 8.0.11
[INFO ] DSRA8205I: JDBC driver name : MySQL Connector/J
[INFO ] DSRA8206I: JDBC driver version : mysql-connector-java-8.0.11 (Revision: 6d4eaa273bc181b4cf1c8ad0821a2227f116fedf)
[INFO ] CWWJP9990I: test/wsjpa:wsjar:file:/home/dwuysan/dev/appservers/wlp/usr/servers/test/apps/expanded/test.war/WEB-INF/lib/d9f2b261-b3c6-4001-8a61-0aaebe46aa99.jar!/_testPU login successful
[INFO ] WELD-000900: 2.4.5 (Final)
[INFO ] FFDC1015I: An FFDC Incident has been created: "org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Defaultat injection point [BackedAnnotatedField] @Inject private id.co.lucyana.test.services.LogService.emat id.co.lucyana.test.services.LogService.em(LogService.java:0)com.ibm.ws.container.service.state.internal.ApplicationStateManager 31" at ffdc_18.06.21_14.11.27.0.log
[INFO ] FFDC1015I: An FFDC Incident has been created: "com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Defaultat injection point [BackedAnnotatedField] @Inject private id.co.lucyana.test.services.LogService.emat id.co.lucyana.test.services.LogService.em(LogService.java:0)com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase 384" at ffdc_18.06.21_14.11.27.1.log
[INFO ] CWWJP9990I: test/wsjpa:wsjar:file:/home/dwuysan/dev/appservers/wlp/usr/servers/test/apps/expanded/test.war/WEB-INF/lib/d9f2b261-b3c6-4001-8a61-0aaebe46aa99.jar!/_testPU logout successful
[ERROR ] CWWKZ0002E: An exception occurred while starting the application test. The exception message was: com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @Defaultat injection point [BackedAnnotatedField] @Inject private id.co.lucyana.test.services.LogService.emat id.co.lucyana.test.services.LogService.em(LogService.java:0)
我们需要关注的两个类是:
package id.co.lucyana.test.util;import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;public class EntityManagerProducer {@PersistenceContext(unitName = "testPU")@Producesprivate EntityManager em;
}
和
package id.co.lucyana.test.services;import id.co.lucyana.test.entity.Log;
import java.util.Collection;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;@Stateless
@LocalBean
public class LogService {@Injectprivate EntityManager em;public Collection<Log> getLogs() {return this.em.createNamedQuery(Log.FIND_ALL, Log.class).getResultList();}
}
问题是,这种方法正在研究这两个TomEE和Wildfly。
任何想法?
PS我在网上遵循某人的建议,即以前使用这种方法,并提出了一个论点,即如果应该更改“ unitName”的名称,则可以在一个位置上完成。 我找不到参考资料了。 我不确定这是否仍然是“好的”方法。 我欢迎任何评论。
翻译自: https://www.javacodegeeks.com/2018/06/openliberty-injection-tomee-wildfly.html