File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes java.lang.RuntimeException: <injection-target> - error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "java.lang.RuntimeException: <injection-target> - error" Watch "java.lang.RuntimeException: <injection-target> - error" New topic
Author

java.lang.RuntimeException: <injection-target> - error

Felix Sima
Ranch Hand

Joined: Feb 06, 2008
Posts: 42
Hello.

During deploying of my ear I get the following error:

java.lang.RuntimeException: <injection-target> could not be found: com.javawebwizard.common.persistence.dao.jpa.BaseDAO.persistentUnitJndi

which really confuses me. I don't know what to check
Any help would be highly appreaciated. Please see the code below:

My JSF managed bean:
public class MagazinBackingBean {
@EJB
MagazinFacade facade;
...



The EJB:
@Stateless
@PersistenceContext(name = BaseDAO.PERSISTENT_UNIT_JNDI_NAME, unitName="magazinPU")
public class MagazinFacadeBean implements MagazinFacade {

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void inregistreazaMagazin(String cif) throws JWWException {
MagazinPO magazin = new MagazinPO();
magazin.setCif(cif);
MagazinDAO dao = new MagazinDAO();
dao.insert(magazin);

}
}


MagazinDAO extends BaseDAO:
package com.javawebwizard.common.persistence.dao.jpa;

public class BaseDAO {
public static final String PERSISTENT_UNIT_JNDI_NAME = "persistentUnitJndi";

@PersistenceContext(name = PERSISTENT_UNIT_JNDI_NAME)
private EntityManager em;
...


The application.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<description>Magazin</description>
<display-name>Magazin</display-name>
<module>
<ejb>Magazin-ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>Magazin-war.war</web-uri>
<context-root>Magazin</context-root>
</web>
</module>
<module>
<java>common.jar</java>>
<- BaseDao is in here!
</module>
</application>


Thanks,
Felix
Use www.jaaava.com - A Google CSE for Java
Felix Sima
Ranch Hand

Joined: Feb 06, 2008
Posts: 42
Hi.

I think I have understood the problem. I create the DAO using the "new" operator, in a method of the ejb.
At this point the DI has been already performed.

I must put



as a field of the ejb, not in my DAO.

Best regards,
Felix
Use www.jaaava.com - A Google CSE for Java
Felix Sima
Ranch Hand

Joined: Feb 06, 2008
Posts: 42
Hi.

I still have the error. The solution described in the last post, did not solve my problem

Best regards,
Felix
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
@Felix Sima
As you have already identified, dependency injection will work only in managed classes and 'MagazinDAO' is'nt a managed class. As for the error still coming, could you post the persistence.xml you used to configure the datasource.


Thanks and Regards
Felix Sima
Ranch Hand

Joined: Feb 06, 2008
Posts: 42
Hello.

Now it finally works

From my tests it seems that the <injection-target> could not be found ... error is launched when



annotation is used outside of a managed component.

I also had an error in my persistence.xml. I used "jdbc/someDS" instead of "java:/someDS". I'm using JBoss 5.0.0.GA application server.
Thank you.

Best regards,
Felix
Use www.jaaava.com - A Google CSE for Java
 
jQuery in Action, 2nd edition
 
subject: java.lang.RuntimeException: <injection-target> - error