I have a Spring Boot application, in which I use "prototype" beans. I know it is possible to inject parameters through constructors arguments but I would like to avoid the approach, as I have a number of additional configuration parameters, including other Beans AND my per-instace parameters.
public class FooBar {
// singleton beans that are shared between multiple instances of this class
private FooRepository fooRepository;
private BarRepository barRepository;
// instance specific settings that are SPECIFIC to the instance of this class
private String fooParameter;
private String barParameter;
private String parameterX;
private String parameterY;
private String parameterZ;
//...
}
@Configuration
public class AppConfig {
/* @Bean definition of FooRepository, BarRepository etc */
@Bean
@Scope(value = "prototype")
public FooBar getFoobar(
FooRepository fooRepository, BarRepository barRepository,
String fooParameter, String barParameter, String parameterX /* ... */) {
// works, but I want to avoid something like this
return new new Foobar(fooRepository, barRepository,
fooParameter, barParameter, parameterX, /* ... */);
}
@Bean
@Scope(value = "prototype")
public FooBar getFoobar(HashMap<String, String> moreParameters) {
Foobar foobar = new Foobar();
// inject parameters without having to implement setter calls
// I want to inject BOTH Spring Beans here and some config parameters
return foobar;
}
}
Is there any way to get Spring to do the Autowiring from its internal set of Beans AND my provided parameters as well? I want to avoid having to setter calls completely.