Spring EJB 远程
Spring EJB remote
我需要帮助才能从动态 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>
我的组件界面
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
记录如下link:
https://docs.jboss.org/author/display/WFLY8/JNDI+Reference?_sscc=t
你的 JNDI 名称应该是这样的:
ejb:myapp/myejbjar/MyEjbName!com.test.MyRemoteInterface
我需要帮助才能从动态 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>
我的组件界面
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
记录如下link: https://docs.jboss.org/author/display/WFLY8/JNDI+Reference?_sscc=t 你的 JNDI 名称应该是这样的: ejb:myapp/myejbjar/MyEjbName!com.test.MyRemoteInterface