if 2 class implements same interface and now i planned to add both the component in ioc java

The solution for “if 2 class implements same interface and now i planned to add both the component in ioc java” can be found here. The following code will assist you in solving the problem.

The use of @Qualifier will solve the issue.
Explained as below example :
public interface PersonType {} // MasterInterface

@Component(value=”1.2″)
public class Person implements PersonType { //Bean implementing the interface
@Qualifier(“1.2″)
public void setPerson(PersonType person) {
this.person = person;
}
}

@Component(value=”1.5”)
public class NewPerson implements PersonType {
@Qualifier(“1.5”)
public void setNewPerson(PersonType newPerson) {
this.newPerson = newPerson;
}
}

Now get the application context object in any component class :

Object obj= BeanFactoryAnnotationUtils.qualifiedBeanOfType((ctx).getAutowireCapableBeanFactory(), PersonType.class, type);//type is the qualifier id

you can the object of class of which qualifier id is passed.

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in