With an XML configured Spring bean factory, I can easily instantiate multiple instances of the same class with different parameters. How can I do the same with annotations?
Continuing @espen answer, injecting beans with qualifiers and configuring them differently with external values.
public class Person{
@Configuration
public static class PersonConfig{
@Bean
//@Qualifier("personOne") - doesn't work - bean qualifier is method name
public Person personOne() {
return new Person("Joe", "Smith");
}
@Bean
//@Qualifier("personTwo") - doesn't work - bean qualifier is method name
public Person personTwo(@Value("${myapp.second.lastName}") String lastName) {
return new Person("Mary", lastName);
}
}
/* blah blah */
}
@Component
public class SomePersonReference{
@Autowired
@Qualifier("personTwo")
Person marry;
}