Luciano Borges
Luciano Borges

Reputation: 827

More than one ejb found with interface of type for binding

I have an interface like this:

@Local
public interface MyInterface {
}

And two classes that implements this interface:

@Singleton
public class FirstBean implements MyInterface {
}

@Singleton
public class SecondBean implements MyInterface {
}

And another class like below:

@Singleton
public class ThirdBean {

    @EJB
    private MyInterface xpto;

}

And i am receiving the following error on deploy:

More than one ejb found with interface of type for binding

How to solve it?

Upvotes: 1

Views: 1318

Answers (1)

aggredi
aggredi

Reputation: 426

Try to use qalifier

@java.lang.annotation.Documented
@java.lang.annotation.Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE,ElementType.FIELD})
@javax.inject.Qualifier
public @interface First {

}

Mark bean using this qualifier

@Singleton
@First
public class FirstBean implements MyInterface {
}

Then inject it

@Singleton
public class ThirdBean {

    @Inject
    @First
    private MyInterface xpto;

}

Upvotes: 2

Related Questions