While I was working on this blog, I encountered this error:
[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 @Default at injection point [BackedAnnotatedField] @Inject private id.co.lucyana.test.services.LogService.em at 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 @Default at injection point [BackedAnnotatedField] @Inject private id.co.lucyana.test.services.LogService.em at 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 @Default at injection point [BackedAnnotatedField] @Inject private id.co.lucyana.test.services.LogService.em at id.co.lucyana.test.services.LogService.em(LogService.java:0)
The two classes we need to focus on are:
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")
@Produces
private EntityManager em;
}AND
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 {
@Inject
private EntityManager em;
public Collection<Log> getLogs() {
return this.em.createNamedQuery(Log.FIND_ALL, Log.class).getResultList();
}
}The thing is, this approach is working on both TomEE and Wildfly.
Any thought?
P.S. I was following someone’s recommendation on the net, of using this approach previously, with the argument that if one should ever change the name of ‘unitName’, it can be done on one single spot. I couldn’t find the reference anymore. I am not sure if this is still a ‘good’ approach. I welcome any comment.
| Published on Java Code Geeks with permission by Deny Wuysan, partner at our JCG program. See the original article here: OpenLiberty: Error on Injection, works on TomEE and Wildfly Opinions expressed by Java Code Geeks contributors are their own. |
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Thank you!
We will contact you soon.
Tags
JPA Open Liberty TomEE Wildfly
This site uses Akismet to reduce spam. Learn how your comment data is processed.
What could help is to place beans.xml inside Manifest folder with
<beans bean-discovery-mode="all" …