(AS7)在参数中使用代理的CDI bean调用远程EJB方法时出错 [英] (AS7) Error calling remote EJB method with proxified CDI bean in parameter
问题描述
我可以在参数方法中使用CDI bean调用远程EJB方法吗?
Can I call a remote EJB method with CDI bean in parameter method?
像这样:
我有一个 LoggedUserProducer.java ,它从数据库中产生了一个用户。
I have a LoggedUserProducer.java thats produces a User from the database.
public class LoggedUserProducer {
@Produces
@SessionScoped
@LoggedUser
public User produceLoggedUser() throws Exception {
... //load user from database with a request token
return user;
}
}
我有一个JSF Bean,可以调用EJB :
And I have a JSF Bean thats make the EJB call:
CarController.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
I don't know why my remote EJB can't find the class com.mycompany.portalcarweb.client.model.User$Proxy$_$$_WeldClientProxy
我的 User.java 部署在JBoss 7模块中。
我的EJB客户端和服务器在 WEB-INF
文件夹中有 jboss-deployment-structure.xml
声明访问该类的正确模块。
My User.java is deployed in a JBoss 7 module.
My EJB client and server have the jboss-deployment-structure.xml
in WEB-INF
folder and declaring the correct module to access this class.
谢谢(抱歉,我的英语)。
Thanks (sorry my english).
更新
我的两个Web应用程序打包在WARs文件中。
My two webapps are packaged in WARs file.
推荐答案
您的JSF Bean不受CDI管理(@ViewScoped仅适用于JSF),除非您使用的是Seam 3之类的东西, CODI或编写了自己的新@ViewScoped。
Your JSF bean isn't being managed by CDI (@ViewScoped is JSF only), unless you're using something like Seam 3, CODI or wrote your own new @ViewScoped.
编辑:实际上,这可能不是bug。每次处理远程EJB时,都必须传递一个副本,这是最好的方法。
Actually, it probably isn't a bug. You'll have to pass a copy, any time you're dealing with remote EJBs copies are the best way to go.
这篇关于(AS7)在参数中使用代理的CDI bean调用远程EJB方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!