-
1. Re: EJB instance is null
jaysensharma Jul 11, 2012 2:34 PM (in response to c.kulkarni)Hi,
What is the JNDI name which you are trying to lookup? using @EJB annotation
Please refer to the following link for an example of @EJB(lookup="something")
http://middlewaremagic.com/jboss/?p=813
And
Invoking a Local Stateless Bean from a Servlet in JBoss AS7 http://middlewaremagic.com/jboss/?p=822
NameNotFound will occur if you will enter a wrong lookup name , Please refer to the following link to know about the EE6 specific portable JNDI Names: http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html
-
2. Re: EJB instance is null
wdfink Jul 11, 2012 2:33 PM (in response to c.kulkarni)Could you provide a bit more informations?
Use
@EJB(lookup="XXX") MyInterface bean;
to inject in your application code.
If the MyInterface is unique @EJB might be enough.
-
3. Re: EJB instance is null
c.kulkarni Jul 11, 2012 2:47 PM (in response to jaysensharma)Hi Jay Kumar,
I am trying to invoke Stateless Bean from an interface.
The Bean is deployed I see in the server log:
JNDI bindings for session bean named stack_configuration in deployment unit subdeployment "web-controller-common-ejb-1.1.22-SNAPSHOT.jar" of deployment "web-controller-ear-1.1.22-SNAPSHOT.ear" are as follows:
java:global/web-controller-ear-1.1.22-SNAPSHOT/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal
java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal
java:module/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal
java:global/web-controller-ear-1.1.22-SNAPSHOT/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration
java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration
java:module/stack_configuration
In the interface I am using JNDI name as :
java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal.
However I don't see any definition for lookup property in EJB.
-
4. Re: EJB instance is null
wdfink Jul 11, 2012 2:52 PM (in response to c.kulkarni)Chaitanya Kulkarni wrote:
I am trying to invoke Stateless Bean from an interface.
In the interface I am using JNDI name as :
java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal.
A interface can not invoke something.
The lookup name should be ejb:app//web-controller-common-ejb-1.1.22-SNAPSHOT//stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal
You will find examples in the documentation:
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance
-
5. Re: EJB instance is null
c.kulkarni Jul 11, 2012 2:53 PM (in response to wdfink)Hi Wolf-Dieter Fink,
The Bean Class looks as following:
@Stateless(name = JndiConstants.STACK_CONFIGURATION, mappedName = JndiConstants.STACK_CONFIGURATION)
@Local(StackConfigurationLocal.class)
@LocalBinding(jndiBinding = JndiConstants.STACK_CONFIGURATION_LOCAL)
public class StackConfigurationEjb implements StackConfigurationLocal {
...code...
}
In the interface I had following code:
private StackConfigurationLocal stackConfigurationLocal;
public StackConfigurationProvider() {
try {
InitialContext initialContext = new InitialContext();
stackConfigurationLocal = (StackConfigurationLocal) initialContext.lookup(JndiConstants.STACK_CONFIGURATION_LOCAL);
logger.debug("site_controller ejb references are acquired");
} catch (Exception fatal) {
logger.error("Couldnot bind web controller interface "+JndiConstants.STACK_CONFIGURATION_LOCAL, fatal);
}
}
Referring to the changes required I changed it to :
@EJB(mappedName=JndiConstants.STACK_CONFIGURATION_LOCAL)
private StackConfigurationLocal stackConfigurationLocal;
public StackConfigurationProvider() {
try {
InitialContext initialContext = new InitialContext();
if(stackConfigurationLocal==null)
{
logger.info("site_controller ejb references is null");
}else
{
logger.info("site_controller ejb references are acquired");
}
//stackConfigurationLocal = (StackConfigurationLocal) initialContext.lookup(JndiConstants.STACK_CONFIGURATION_LOCAL);
} catch (Exception fatal) {
logger.error("Couldnot bind web controller interface "+JndiConstants.STACK_CONFIGURATION_LOCAL, fatal);
}
}
=========================================
I see in the logs that ejb reference is null. I used mappedName as I could not find lookup property.
Thanks
-
6. Re: EJB instance is null
c.kulkarni Jul 11, 2012 3:09 PM (in response to wdfink)I changes the Jndiname to java:app/web-controller-common-ejb-1.1.22-SNAPSHOT/stack_configuration!com.service.gis.sitecontroller.ejb.StackConfigurationLocal.
However I am getting the nullpointerexception when calling a method on it. So the reference is still null.
Also currently I am using the local interface.
Also the log says:
Exception sending context initialized event to listener instance of class : xxx java.lang.NullPointerException.
Thanks
-
7. Re: EJB instance is null
wdfink Jul 11, 2012 3:19 PM (in response to c.kulkarni)@Stateless(mappedNmae=...)
will be ignored in AS7.
If you use a local reference in the same container a simple @EJB annotation should be work.
Also please read the documentation from my links above, the naming and lookup process in AS7 will be different to former version.
-
8. Re: EJB instance is null
c.kulkarni Jul 11, 2012 4:48 PM (in response to wdfink)This is how my EJB Class looks like:
@Stateless
public class StackConfigurationEjb implements StackConfigurationLocal {
...code...
}
In the integration part I am using following code:
public class StackConfigurationProvider implements IConfigurationListener {
private Logger logger = LoggerFactory.getLogger(StackConfigurationProvider.class);
@EJB
private StackConfigurationLocal stackConfigurationLocal;
...code...
}
these two classes are in the same ear file.
Below is the log i get from server.log:
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/chi]] (MSC service thread 1-5) Exception sending context initialized event to listener instance of cla
s com.hsl.chi.webapp.ChiLoader: java.lang.NullPointerException
at com.videobet.gis.webcontroller.integration.StackConfigurationProvider.getConfigurationProperty(StackConfigurationProvider.java:40) [web-controller-1.1.22-SNAPSHOT.jar:]
at com.hsl.chi.webapp.ChiLoader.contextInitialized(ChiLoader.java:368) [classes:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_33]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_33]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_33]
I did go though documents and discussions tried to change jndi to java: from ejb: and vice versa.
However it did not help.
Any help would be highly appreciated.
Thanks again.
-
9. Re: EJB instance is null
wdfink Jul 12, 2012 2:49 AM (in response to c.kulkarni)Where this code is deployed? Can you post how the classes are packed and where you use it?
-
10. Re: EJB instance is null
c.kulkarni Jul 12, 2012 10:02 AM (in response to wdfink)The code is deployed in jboss\standalone\deployments. I am using Jboss 7.1
+ site-controller-ear-1.1.22-SNAPSHOT.ear
+ lib
- META-INF
- jboss-deployment-structure.xml
- application.xml
- persistence.xml
- MANIFEST.MF
- jboss-app.xml
- sg.webapp.jboss-1.0.0.war
- persistence-1.0.0.jar
- pkiguiwebapp.war
- pkiwebapp.war
- site-controller-1.2.22-SNAPSHOT.jar
- site-controller-common-ejb-1.2.22-SNAPSHOT.jar
- site-controller-web1.0.
EJBs are in
site-controller-1.2.22-SNAPSHOT.jar, site-controller-common-ejb-1.2.22-SNAPSHOT.jar. The particular one we are discussing is in site-controller-common-ejb-1.2.22-SNAPSHOT.jar and classes in sg.webapp.jboss-1.0.0.war call integration class StackConfigurationProvider (code in previous reply) which is in site-controller-1.2.22-SNAPSHOT.jar and while calling the method on it nullpointerexception is generated.
Thanks.
-
11. Re: EJB instance is null
jaikiran Jul 13, 2012 2:47 AM (in response to c.kulkarni)ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/chi]] (MSC service thread 1-5) Exception sending context initialized event to listener instance of cla
s com.hsl.chi.webapp.ChiLoader: java.lang.NullPointerException
at com.videobet.gis.webcontroller.integration.StackConfigurationProvider.getConfigurationProperty(StackConfigurationProvider.java:40) [web-controller-1.1.22-SNAPSHOT.jar:]
at com.hsl.chi.webapp.ChiLoader.contextInitialized(ChiLoader.java:368) [classes:]
What does that ChiLoader class code look like? I'm guessing you are not looking up the bean in that class and instead are perhaps instantiating using the StackConfigurationProvider using the new operator?