我试图弄清楚为什么我需要同时实现这两个接口以避免部署问题.
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|#]
修复?!
如果我更改接口隐式以不仅实现ExtendedExamplePlanAssembler接口,而且还实现父ExamplePlanAssembler接口,则部署错误将消失.
ExtendedExamplePlanAssemblerImpl.java(v2)
@Stateless
public class ExtendedExamplePlanAssemblerImpl
implements ExtendedExamplePlanAssembler, ExamplePlanAssembler{
/* Method impls removed */
}
问题
为什么将父接口添加到我的工具声明中可以解决部署问题?
解决方法:
EJB Spec这样说,
举例来说,特定会话bean公开的客户端视图不会被以下子类继承:
也碰巧定义了一个会话bean.
@Stateless
public class A implements Foo { ... }
@Stateless
public class B extends A implements Bar { ... }
假设Foo和Bar是本地业务接口,并且没有关联的部署描述符,
会话Bean A公开本地业务接口Foo,会话Bean B公开本地业务接口
吧,但不行.
参考here.EJB3.1Spec的4.9.2.1节