(AS7)在参数中使用代理的CDI bean调用远程EJB方法时出错

时间:2013-04-24 23:00:31

标签: java-ee jboss7.x cdi ejb-3.1 proxy-classes

我可以在参数方法中使用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调用:

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

我的 User.java 部署在JBoss 7模块中。 我的EJB客户端和服务器在jboss-deployment-structure.xml文件夹中有WEB-INF,并声明访问此类的正确模块。

谢谢(对不起我的英文)。


更新

我的两个webapps打包在WARs文件中。

1 个答案:

答案 0 :(得分:0)

您的JSF bean不受CDI管理(@ViewScoped仅限JSF),除非您使用的是Seam 3,CODI或编写自己的新@ViewScoped。

编辑:实际上,它可能不是一个错误。您必须传递副本,每当您处理远程EJB时,副本都是最好的方法。