我想弄清楚为什么我需要实现这两个接口(interface)以避免部署问题。
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|#]
修复?!
如果我更改我的接口(interface) impl 以不仅实现 ExtendedExamplePlanAssembler
接口(interface),而且还实现父级 ExamplePlanAssembler
接口(interface),我的部署错误就会消失。
ExtendedExamplePlanAssemblerImpl.java (v2)
@Stateless
public class ExtendedExamplePlanAssemblerImpl
implements ExtendedExamplePlanAssembler, ExamplePlanAssembler{
/* Method impls removed */
}
问题
为什么将父接口(interface)添加到我的implements
声明可以解决部署问题?
最佳答案
EJB 规范是这样说的,
例如,特定 session bean 公开的客户端 View 不会被子类继承 也恰好定义了一个 session bean。
@Stateless
public class A implements Foo { ... }
@Stateless
public class B extends A implements Bar { ... }
假设 Foo 和 Bar 是本地业务接口(interface)并且没有关联的部署描述符, session bean A暴露本地业务接口(interface)Foo,session bean B暴露本地业务接口(interface) Bar,但不是 Foo。
引用 here . EJB3.1规范4.9.2.1节
关于java - 获取无法解析引用本地 ejb-ref 未实现父接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12823527/