java 获取无法解析引用本地 ejb-ref 未实现父接口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12823527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting Cannot resolve reference Local ejb-ref not implementing parent interface
提问by Snekse
I'm trying to figure out why I need to implement both of these interfaces in order to avoid deployment issues.
我试图弄清楚为什么我需要实现这两个接口以避免部署问题。
Java Code
Java代码
ExamplePlanAssembler.java
ExamplePlanAssembler.java
@Local
public interface ExamplePlanAssembler {
ExamplePlan toBO(ExamplePlanEntity entity);
}
ExtendedExamplePlanAssembler.java
ExtendedExamplePlanAssembler.java
@Local
public interface ExtendedExamplePlanAssembler
extends ExamplePlanAssembler{
ExtExamplePlan toBO(ExamplePlanEntity entity, ExtExamplePlanEntity extEntity);
}
ExtendedExamplePlanAssemblerImpl.java
ExtendedExamplePlanAssemblerImpl.java
@Stateless
public class ExtendedExamplePlanAssemblerImpl
implements ExtendedExamplePlanAssembler {
/* Method impls removed */
}
ExamplePlanServiceImpl.java
ExamplePlanServiceImpl.java
@Stateless
public class ExamplePlanServiceImpl
implements ExamplePlanService {
private ExamplePlanAssembler examplePlanAssembler ;
@EJB
public void setAssembler(ExamplePlanAssembler examplePlanAssembler) {
this.examplePlanAssembler = examplePlanAssembler;
}
}
Deployment Error
部署错误
[#|.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|#]
The Fix?!
修复?!
If I change my interface impl to implement not only the ExtendedExamplePlanAssembler
interface, but also the parent ExamplePlanAssembler
interface, my deployment error disappears.
如果我更改接口实现不仅实现ExtendedExamplePlanAssembler
接口,还实现父ExamplePlanAssembler
接口,我的部署错误就会消失。
ExtendedExamplePlanAssemblerImpl.java (v2)
ExtendedExamplePlanAssemblerImpl.java (v2)
@Stateless
public class ExtendedExamplePlanAssemblerImpl
implements ExtendedExamplePlanAssembler, ExamplePlanAssembler{
/* Method impls removed */
}
The Question
问题
Whydoes adding the parent interface to my implements
declaration resolve deployment issues?
为什么将父接口添加到我的implements
声明中可以解决部署问题?
采纳答案by Maddy
EJB Spec says so,
EJB 规范是这么说的,
As an example, the client views exposed by a particular session bean are not inherited by a subclass that also happens to define a session bean.
例如,由特定会话 bean 公开的客户端视图不会被同样定义会话 bean 的子类继承。
@Stateless
public class A implements Foo { ... }
@Stateless
public class B extends A implements Bar { ... }
Assuming Foo and Bar are local business interfaces and there is no associated deployment descriptor, session bean A exposes local business interface Foo and session bean B exposes local business interface Bar, but not Foo.
假设 Foo 和 Bar 是本地业务接口,并且没有关联的部署描述符,会话 bean A 暴露本地业务接口 Foo,会话 bean B 暴露本地业务接口 Bar,但不暴露 Foo。
Reference here. Section 4.9.2.1 of EJB3.1 Spec
参考这里。EJB3.1 规范的第 4.9.2.1 节
回答by Harvester
you can not extend an interface I need you to try implementing the interface (you can implement both interfaces in the same bean class) but for now you need to replace the keyword "extends" with "implements"
你不能扩展接口我需要你尝试实现接口(你可以在同一个 bean 类中实现两个接口)但现在你需要用“实现”替换关键字“扩展”
@Local
public interface ExtendedExamplePlanAssembler
extends ExamplePlanAssembler{
ExtExamplePlan toBO(ExamplePlanEntity entity, ExtExamplePlanEntity extEntity);
}