开发者

is it not allowed to implement a single local interface by two stateless beans?

I am getting following exception when a Local Interface is implemented by two Stateless beans, in which one having normal functionality 开发者_高级运维and other having some enhanced functionality in it.

java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container UserBean: reference class: org.app.SecurityServiceLocal ejbLink: duplicated in Some.jar


Finally I came to know why I am getting this exception

I have used @EJB annotation to inject a Stateless bean into another Stateless bean Name UserBean with following code

@Stateless(name="UserBean")
@EJB(name="app/SecurityService",
        beanInterface=SecurityServiceLocal.class)
public class UserBean implements UserRemote{

}

If you check the injection details I was injecting SecurityServiceLocal, which was implemented by two Stateless bean classes name SercurityServiceBean and SecurityServiceEnhaBean. So, container is in ambiguity state to decide which bean to inject in as both are implementing same interface.

This can be resolved by specifying some more information like beanName property value in @EJB annotation. There you need to provide which stateless bean class needs to be injected by using bean name(declared at that bean level (or) in ejb-jar.xml). check the code to identify the change in the injection mapping

@Stateless(name="UserBean")
@EJB(name="app/SecurityService",
        beanInterface=SecurityServiceLocal.class,
        beanName="SecurityServiceEnha")
public class UserBean implements UserRemote{

}


It's hard to say for sure without seeing code. A good first step would be to use the optional mappedName="" attribute on your session beans' annotion to give each a unique JNDI name. You'll have to use an equivalent mappedName attribute in your client to make sure you are using the bean that you intent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜