0

我可以在参数方法中使用 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.xmlinWEB-INF文件夹并声明了访问此类的正确模块。

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


更新

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

4

1 回答 1

0

您的 JSF bean 不是由 CDI 管理的(@ViewScoped 仅是 JSF),除非您使用 Seam 3、CODI 之类的东西或编写自己的新 @ViewScoped。

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

于 2013-04-25T21:11:12.597 回答