EJB-annotation does not work, why is that?
Hello,My @EJB-annotation does not work, why is that?
I need help to understand why my bean is null at the breakpoint below.
I have tried some different usage of the @EJB but none seems to get the bean injected/initiated.
To get it initiated I need to do a manually "InitialContext.doLookup".
(My environmen is Java 8 and Weblogic 14)
I got a interface like this:
[/code]
package com.mycompany.cruds.interfaces;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;
import com.mycompany.cruds.domain.Domain;
import com.mycompany.cruds.domain.DomainSearchCriteria;
public interface CRUDS {
public Serializable create(Domain domain) throws NamingException, SQLException;
}
[/code]
...and an other interface like this:
[code]
package com.mycompany.cruds.interfaces;
import javax.ejb.Local;
@Local
public interface CrudSessionLocal extends CRUDS {
public static final String JNDI_NAME = "java:global.cruds-app.server.CrudsSessionBean!com.mycompany.cruds.interfaces.CrudSessionLocal";
}
[/code]
...these are packed in a interfaces.jar
I got a stateless bean like this:
[code]
package com.mycompany.cruds.server;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import javax.ejb.Stateless;
import javax.naming.NamingException;
import com.mycompany.cruds.domain.Domain;
import com.mycompany.cruds.domain.DomainSearchCriteria;
import com.mycompany.cruds.interfaces.CrudSessionLocal;
import com.mycompany.cruds.server.dao.DomainDaoBean;
@Stateless
public class CrudsSessionBean implements CrudSessionLocal {
private DomainDaoBean domainDaoBean = new DomainDaoBean();
public CrudsSessionBean() {
super();
}
@Override
public Serializable create(Domain domain) throws NamingException, SQLException {
Serializable serializable = domainDaoBean.create(domain);
return serializable;
}
}
[/code]
...that is packed in a server.jar
I got a servlet like this:
[code]
package com.mycompany.cruds.web_client;
import java.io.IOException;
import java.sql.SQLException;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mycompany.cruds.domain.LogItem;
import com.mycompany.cruds.domain.LogItem.Level;
import com.mycompany.cruds.interfaces.CrudSessionLocal;
public class CreateServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
//@EJB
//@EJB(beanName = "CrudsSessionBean")
@EJB(lookup = "java:global.cruds-app.server.CrudsSessionBean!com.mycompany.cruds.interfaces.CrudSessionLocal")
private CrudSessionLocal crudSessionLocal;
public CreateServlet() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//BREAKPOINT
if (crudSessionLocal == null) {
try {
crudSessionLocal = (CrudSessionLocal) InitialContext.doLookup(CrudSessionLocal.JNDI_NAME);
} catch (NamingException e) {
}
}
...
[/code]
...that is packed in a web-client.war
All three artifacts are packed in a ear with a application.xml:
[code]
<display-name>app</display-name>
<module>
<ejb>server.jar</ejb>
</module>
<module>
<web>
<web-uri>web-client.war</web-uri>
<context-root>/web-client</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
[/code]
...inside lib/ is the interfaces.jar of course.
Do you guys see why the @EJB-annotation does not work?
Best regards
Fredrik