我可以在参数方法中使用 CDI bean 调用远程 EJB 方法吗?
像这样:
我有一个LoggedUserProducer.java,它从数据库中生成一个用户。
public class LoggedUserProducer {
@Produces
@SessionScoped
@LoggedUser
public User produceLoggedUser() throws Exception {
... //load user from database with a request token
return user;
}
}
我有一个 JSF Bean,它可以进行 EJB 调用:
汽车控制器.java
@Named
@ViewScoped
public class CarController implements Serializable {
@Inject //I have a producer to create the EJB proxy
private RepairRemote repairRemote; //My remote EJB
@Inject
@LoggedUser
private User loggedUser; //my User produced by LoggedUserProducer
private Car car;
public void repairCar() throws Exception {
... //some actions...
Repair repair = new Repair(this.car)
repair.setPerformedBy(loggedUser); //setting my proxified cdi bean into a POJO
repairRemote.repair(repair); //here throws ClassNotFoundException;
}
和例外:
java.lang.RuntimeException: ClassNotFoundException marshaling EJB parameters
at org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:229)
at org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:216)
...
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
at org.jboss.weld.proxies.RepairRemote$-248248579$Proxy$_$$_WeldClientProxy.repair(RepairRemote$-248248579$Proxy$_$$_WeldClientProxy.java)
at com.mycompany.services.controller.CarController.repairCar(CarController.java:118)
at com.mycompany.services.controller.CarController$Proxy$_$$_WeldSubclass.repairCar(CarController$Proxy$_$$_WeldSubclass.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
...
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: com.mycompany.portalcarweb.client.model.User$Proxy$_$$_WeldClientProxy from [Module "deployment.portalcarweb.war:main" from Service Module Loader]
我不知道为什么我的远程 EJB 找不到类com.mycompany.portalcarweb.client.model.User$Proxy$_$$_WeldClientProxy
我的User.java部署在 JBoss 7 模块中。我的 EJB 客户端和服务器具有jboss-deployment-structure.xml
inWEB-INF
文件夹并声明了访问此类的正确模块。
谢谢(对不起我的英语)。
更新
我的两个 webapps 打包在 WARs 文件中。