I'm trying to specialize an EJB. I have
package com.foo.core;
@Stateless
public class MyFacade { }
and
package com.foo.extension;
@Specializes
@Stateless
public class MyFacade extends com.foo.core.MyFacade { }
In my opinion, this should work, because the meaning of @Specializes is, that CDI should forget about the core-class and instead use the specialized class. I also found this bug https://issues.jboss.org/browse/WELD-1451 which indicates, that it is possible to specialize an EJB.
But if i try to deploy my application (I'm using Weblogic 12.1.3), I always get
weblogic.utils.ErrorCollectionException: There are 1 nested errors: weblogic.j2ee.dd.xml.AnnotationProcessException: Duplicate ejb name 'MyFacade' found: annotation 'Stateless' on bean class com.foo.core.MyFacade and annoation 'Stateless' on bean class com.foo.extension.MyFacade
Am I doing anything wrong?
Thanks!
The exception message you quoted is caused by a name conflict, which is not directly related to CDI at all: each EJB can be addressed by a number of different JNDI names, and some of them (e.g. java:module/MyFacade
) only include the simple class name, not the package name. So you cannot have two EJBs with the same name in different packages.
Adding CDI and @Specializes
may prevent the specialized EJB from showing up in the CDI container, but it is still an EJB.
You can try to rename your derived class - this should solve the duplicate name issue, but I'm not sure it will solve your overall problem.