3

我试图弄清楚为什么我需要实现这两个接口以避免部署问题。

Java 代码

ExamplePlanAssembler.java

@Local
public interface ExamplePlanAssembler {
   ExamplePlan toBO(ExamplePlanEntity entity);
}

ExtendedExamplePlanAssembler.java

@Local
public interface ExtendedExamplePlanAssembler 
extends ExamplePlanAssembler{
   ExtExamplePlan toBO(ExamplePlanEntity entity, ExtExamplePlanEntity extEntity);
}

ExtendedExamplePlanAssemblerImpl.java

@Stateless
public class ExtendedExamplePlanAssemblerImpl 
implements ExtendedExamplePlanAssembler {
   /* Method impls removed */
}

ExamplePlanServiceImpl.java

@Stateless
public class ExamplePlanServiceImpl 
implements ExamplePlanService {
   private ExamplePlanAssembler examplePlanAssembler ;
   @EJB
   public void setAssembler(ExamplePlanAssembler examplePlanAssembler) {
       this.examplePlanAssembler = examplePlanAssembler;
    }
}

部署错误

[#|.507-0500|SEVERE|gf3.1.2|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common
|_ThreadID=83;_ThreadName=Thread-7;|Cannot resolve reference Local ejb-ref name=
com.myco.services.business.ExampleServiceImpl/examplePlanAssembler,Local 3.x interface =
com.myco.services.assembly.ExamplePlanAssembler,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session|#]

[#|.508-0500|SEVERE|gf3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server
|_ThreadID=83;_ThreadName=Thread-7;|Exception while deploying the app [mycoservicesear]|#]

[#|.508-0500|SEVERE|gf3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server
|_ThreadID=83;_ThreadName=Thread-7;|Cannot resolve reference Local ejb-ref name=
com.myco.services.business.ExampleServiceImpl/examplePlanAssembler,Local 3.x interface =
com.myco.services.assembly.ExamplePlanAssembler,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session
java.lang.RuntimeException: Cannot resolve reference Local ejb-ref name=
com.myco.services.business.ExampleServiceImpl/examplePlanAssembler,Local 3.x interface =
com.myco.services.assembly.ExamplePlanAssembler,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session


[#|.516-0500|SEVERE|gf3.1.2|javax...gf.deployment.admin
|_ThreadID=83;_ThreadName=Thread-7;|Exception while deploying the app [mycoservicesear] : Cannot resolve reference Local ejb-ref name=
com.myco.services.business.ExampleServiceImpl/examplePlanAssembler,Local 3.x interface =
com.myco.services.assembly.ExamplePlanAssembler,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session|#]

修复?!

如果我将接口 impl 更改为不仅实现ExtendedExamplePlanAssembler接口,还实现父ExamplePlanAssembler接口,我的部署错误就会消失。

ExtendedExamplePlanAssemblerImpl.java (v2)

@Stateless
public class ExtendedExamplePlanAssemblerImpl 
implements ExtendedExamplePlanAssembler,  ExamplePlanAssembler{
   /* Method impls removed */
}

问题

为什么将父接口添加到我的implements声明中可以解决部署问题?

4

2 回答 2

4

EJB 规范是这么说的,

例如,由特定会话 bean 公开的客户端视图不会被恰好定义会话 bean 的子类继承。

@Stateless
public class A implements Foo { ... }
@Stateless
public class B extends A implements Bar { ... }

假设 Foo 和 Bar 是本地业务接口并且没有关联的部署描述符,会话 bean A 公开本地业务接口 Foo,会话 bean B 公开本地业务接口 Bar,但不公开 Foo。

参考这里。EJB3.1 规范第 4.9.2.1 节

于 2012-10-11T13:09:06.280 回答
0

你不能扩展接口我需要你尝试实现接口(你可以在同一个 bean 类中实现两个接口)但是现在你需要用“实现”替换关键字“扩展”

@Local
public interface ExtendedExamplePlanAssembler 
 extends ExamplePlanAssembler{
  ExtExamplePlan toBO(ExamplePlanEntity entity, ExtExamplePlanEntity  extEntity);
}
于 2016-03-05T05:28:57.933 回答