This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Jboss + Spring + Ejb (Null Pointer Exception Problem)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all. I am new to Ejb. i successfully deployed my ejb in jboss 4.0 and now trying to access session bean and getting error

(xml.XmlBeanDefinitionReader 293 ) Loading XML bean definitions from file [c:\client-spring-stateless-ejb.xml]
Exception in thread "main" java.lang.NullPointerException
at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:133)
at $Proxy0.create(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.create(AbstractSlsbInvokerInterceptor.java:177)
at org.springframework.ejb.access.LocalSlsbInvokerInterceptor.newSessionBeanInstance(LocalSlsbInvokerInterceptor.java:131)
at org.springframework.ejb.access.LocalSlsbInvokerInterceptor.getSessionBeanInstance(LocalSlsbInvokerInterceptor.java:105)
at org.springframework.ejb.access.LocalSlsbInvokerInterceptor.invoke(LocalSlsbInvokerInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:203)
at $Proxy1.sayHello(Unknown Source)
at com.glamour.client.EjbClient.main(EjbClient.java:13)


--------ejb-jar.xml-------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>HelloServiceEjb</ejb-name>
<local-home>com.glamour.ejb.HelloServiceHome</local-home>
<local>com.glamour.ejb.HelloServiceLocal</local>
<ejb-class>com.glamour.ejb.HelloServiceEjb</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>spring-stateless-ejb</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</ejb-jar>

--------jboss.xml-------
<jboss>
<enterprise-beans>
<session>
<ejb-name>HelloServiceEjb</ejb-name>
<local-jndi-name>ejb/helloService</local-jndi-name>
</session>
</enterprise-beans>
</jboss>
---------------
package com.glamour.ejb;
public interface HelloService {
public String sayHello();
}


package com.glamour.ejb;
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
public interface HelloServiceHome extends EJBLocalHome{

public HelloServiceLocal create() throws CreateException;
}


package com.glamour.ejb;
import javax.ejb.EJBLocalObject;
public interface HelloServiceLocal extends HelloService,EJBLocalObject {

}


package com.glamour.ejb;
public class HelloServiceImpl implements HelloService{

public String sayHello(){
return "hello Spring";
}
}


package com.glamour.ejb;
import javax.ejb.CreateException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.ejb.support.AbstractStatelessSessionBean;
public class HelloServiceEjb extends AbstractStatelessSessionBean implements HelloService {

private HelloService helloService;

protected void onEjbCreate() throws CreateException {
BeanFactory beanFactory = getBeanFactory();
helloService = (HelloService)beanFactory.getBean("helloService");
}

public String sayHello(){
return helloService.sayHello();
}
}

--------------------spring-stateless-ejb.xml----
<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="helloService" class="com.glamour.ejb.HelloServiceImpl"></bean>
</beans>
-----------------EjbClient.java--------
package com.glamour.client;
import com.glamour.ejb.*;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class EjbClient {

public static void main(String[] args) {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource("c:\\client-spring-stateless-ejb.xml"));
HelloService hs = (HelloService) factory.getBean("helloServiceBean");
System.out.println(hs.sayHello());
}
}

-----------------------client-spring-stateless-ejb.xml-----------

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">

<jee:local-slsb id="helloServiceBean"
jndi-name="ejb/helloService"
business-interface="com.glamour.ejb.HelloService"
cache-home="true">
<jee:environment>
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
</jee:environment>
</jee:local-slsb>
</beans>



springError.JPG
[Thumbnail for springError.JPG]
Structure
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rakesh,

Can't access an EJB's local interface from another VM (that's why it's called local). Your client is a separate VM here. If you're sure your EJB's always going to be used by locally deployed components, then test using a locally deployed servlet or JSP. Else, provide a remote interface.

Also, can you please enclose all the code in [ code ] [ /code ] tags in your post...it makes it much easier to read your post then.

Cheers
Karthik
 
rakesh maheshwari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karthik,

I Changed local interface to remote. Now its working fine. Next time i will take care of code tag. i am too from pesit 2009. thanks a lot

Regards
Rakesh
 
Everybody's invited. Even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!