Results 1 to 2 of 2

Thread: Jboss + Spring + Ejb (Null Pointer Exception Problem)

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Default Jboss + Spring + Ejb (Null Pointer Exception Problem)

    Hello all, I am new to ejb and spring. I am trying to access ejb deployed in jboss server 4.0 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(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.ejb.access.AbstractSlsbInvoker Interceptor.create(AbstractSlsbInvokerInterceptor. java:177)
    at org.springframework.ejb.access.LocalSlsbInvokerInt erceptor.newSessionBeanInstance(LocalSlsbInvokerIn terceptor.java:131)
    at org.springframework.ejb.access.LocalSlsbInvokerInt erceptor.getSessionBeanInstance(LocalSlsbInvokerIn terceptor.java:105)
    at org.springframework.ejb.access.LocalSlsbInvokerInt erceptor.invoke(LocalSlsbInvokerInterceptor.java:6 1)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :161)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:203)
    at $Proxy1.sayHello(Unknown Source)
    at com.glamour.client.EjbClient.main(EjbClient.java:1 3)

    ------------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>

    ---------EjbClient.java-------
    package com.glamour.client;
    import com.glamour.ejb.*;

    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFacto ry;
    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.xm---------------
    <?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/schem...-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.Nam ingContextFactory
    java.naming.provider.url=jnp://localhost:1099
    java.naming.factory.url.pkgs=org.jboss.naming:org. jnp.interfaces
    </jee:environment>
    </jee:local-slsb>
    </beans>

    -----------------------HelloServiceHome----------
    package com.glamour.ejb;

    import javax.ejb.CreateException;
    import javax.ejb.EJBLocalHome;

    public interface HelloServiceHome extends EJBLocalHome{

    public HelloServiceLocal create() throws CreateException;
    }
    --------------------HelloServiceLocal-----------
    package com.glamour.ejb;


    import javax.ejb.EJBLocalObject;

    public interface HelloServiceLocal extends HelloService,EJBLocalObject {

    }

    ----------------------HelloServiceImpl----------
    package com.glamour.ejb;

    public class HelloServiceImpl implements HelloService{

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

    ------------HelloServiceEjb-------------
    package com.glamour.ejb;

    import javax.ejb.CreateException;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.ejb.support.AbstractStatelessS essionBean;

    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>

  2. #2

    Default

    One thing to note is that you can access local EJBs only if accessing from the same application server/jvm. If you are trying to access an EJB from outside the server like from a main method you have to use the remote interface. I will try your example with remote interface time permitting. I hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •