File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Jboss + Spring  + Ejb (Null Pointer Exception Problem) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Jboss + Spring  + Ejb (Null Pointer Exception Problem)" Watch "Jboss + Spring  + Ejb (Null Pointer Exception Problem)" New topic
Author

Jboss + Spring + Ejb (Null Pointer Exception Problem)

rakesh maheshwari
Greenhorn

Joined: Apr 02, 2010
Posts: 2
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.namingrg.jnp.interfaces
</jee:environment>
</jee:local-slsb>
</beans>






[Thumbnail for springError.JPG]

Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 529
    
    6
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

Joined: Apr 02, 2010
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jboss + Spring + Ejb (Null Pointer Exception Problem)