Spring EJB远程

时间:2015-08-22 17:28:29

标签: spring ejb invoke

我需要帮助从动态Web项目(spring)调用EJB Remote(EJB项目DAO)。我使用WildFly 8服务器

在EJB项目中

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);
            }

在Web项目中

应用程序上下文

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

public interface MyComponent {


    public void addPerson(Person p);

}

控制器

@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";

    }
}

控制台

   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

1 个答案:

答案 0 :(得分:0)

重新注册以下链接: https://docs.jboss.org/author/display/WFLY8/JNDI+Reference?_sscc=t 您的JNDI名称应该是: EJB:MyApp的/ myejbjar / MyEjbName com.test.MyRemoteInterface