Search code examples
javaejbapache-tomee

Multiple EJB beans with same name


We have two EJB beans that have the same name (say MyBean) but are in different packages (different sub modules), say com.example.module1 and com.example.module2 and they implement entirely different interfaces. Apache TomEE+ 1.7.2 recognizes only one of them randomly on each deploy and completely ignores the other one, not even a warning!

Tried changing openejb.deploymentId.format property in the conf/system.properties to the two below, but that didn't help.

openejb.deploymentId.format = {appId}/{ejbJarId}/{ejbName}

openejb.deploymentId.format = {appId}/{ejbJarId}/{ejbClass}

Anyone know how to fix this problem? Thanks much


Solution

  • Have you tried setting a name for each?

    @Stateless(name="MyBean1")
    public class MyBean implements MyBeanLocal
    

    or annotations

    @Documented
    @Qualifier
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
    public @interface TypeOne {
    
    }
    
    @Documented
    @Qualifier
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
    public @interface TypeTwo {
    
    }
    
    
    @TypeOne
    @Stateless
    public class MyBean implements MyBeanLocal
    
    @TypeTwo
    @Stateless
    public class MyBean implements MyBeanLocal