EJB Dependency Injection with interface

I have an interface I with method m and two concrete implementations A and B.

public interface I{
   public void m();
}
public class A implements I{
  public void m(){
    //
   }
}
public class B implements I{
    public void m(){
     //
    }
}

I want to know when I inject I which of the two methods will be executed

@EJB
private I service;
///
service.m();
/////

Answers


None of them, it will become into an error since the application server doesn't know which implementation to use. To avoid this, just provide the id of the class implementation, which by default is the same name of the class but starting with lower case:

//uncomment one of these
//@EJB(name="a")
//@EJB(name="b")
private I service;

Need Your Help

How to get count of days?

c# asp.net

I want to count the total days in between two dates( including start date and end date).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.