1 Reply Latest reply on Aug 24, 2015 7:59 AM by tomekadamski

    EJB remote invoke in spring

    mahmoud fessi Newbie

      Hi,

       

      I need help to call EJB Remote (EJB project DAO) from dynamic web project (spring). i use a WildFly 8 server

       

      IN EJB project

       

      PersonDaoRemote

       

      @Remote

      public interface PersonDaoRemote {

       

       

      public void addPerson(Person p);

       

       

      }

       

      PersonDaoImpl

       

      @Stateless @RemoteBinding(jndiBinding="PersonDao")

       

      public class PersonDaoImpl implements PersonDaoLocal,PersonDaoRemote{

       

      @PersistenceContext(unitName="UniQPersistence") private EntityManager em;

      @Override public void addPerson(Person p) { em.persist(p);

      }

      In Web project

       

      Application-context

       

      <bean id="myComponent"

      class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">

      <property name="jndiName" value="ejb/PersonDao"/>

      <property name="businessInterface" value="com.mycom.MyComponent"/>

      </bean>

       

      <bean id="SecurityController" class="com.uniqweb.controller.SecurityController">

      <property name="myComponent" ref="myComponent"/>

      </bean>

       

      Mycomponent interface

       

      public interface MyComponent {

       

       

      public void addPerson(Person p);

       

      }

       

      controller

       

      @Controller

      public class SecurityController {

      private MyComponent myComponent;

       

      public void setMyComponent(MyComponent myComponent) {

      this.myComponent = myComponent;

      }

       

       

      @RequestMapping(value = "/addtest",params="submit", method = RequestMethod.POST)

      public String test(ModelMap model,@RequestParam(value = "error", required = false) String error,

      @RequestParam("username") String logout) {

       

      System.out.println(logout);

       

      Person p=new Person();

      p.setId(1);

      myComponent.addPerson(p); line66

       

       

      return "login";

       

      }

      }

      console

       

      Caused by: java.lang.NullPointerException

      at com.uniqweb.controller.SecurityController.login3(SecurityController.java:66) [classes:]

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_45]

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_45]

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_45]

      at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_45]

      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]

      ... 30 more