I'm working on an application using EJB3, JPA and JSF and I'd like to inject my DAO into the EJB using CDI :
Here's my DAO's code :
public class ZoneDao {
@PersistenceContext(unitName = "wabApp3PU")
private EntityManager em;
/* Functions */
}
and here's my EJB code :
@Stateless
public class ZoneFacade{
@Inject
private ZoneDao zoneDao;
/* Functions*/
}
Here's the error I get :
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [ZoneDao] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private fr.si.metier.ZoneFacade.zoneDao]
NB: I'm using the glassfish 4 application server
JAVA EE 6-CDI组件,给DAO @ApplicationScoped,然后它将允许注入持久性上下文
Add @Stateless
to your ZoneDao
Class or give this Bean a Scope eg @SessionScoped
.
Make sure you have a beans.xml if using Java EE 6. With version 7 it is not required anymore.
ZoneDao is not marked as a managed bean and so it won't work like that using CDI. Annotate ZoneDao with @Named , and choose it's scope using @RequestScope, @SessionScop,...etc or what ever scope you need, Only then it will be a managed bean that can be injected using CDI.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.