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?
Should you need to inject, in the new created object, beans or properties from the spring context, you can have a look at the following section of code in which I have extended the Espen answer by injecting a bean which is created from the spring context:
@Configuration
public class PersonConfig {
@Autowired
private OtherBean other;
@Bean
public Person personOne() {
return new Person("Joe", "Smith", other);
}
}
Have a look at this article for all the possibile scenarios.