I want to create a prototyped bean with some custom parameter using an ObjectFactory. At the place where I need my bean I have the following:
private final ObjectProvider<Installation> installationProvider;
public void test() {
Installation installation = installationProvider.getObject("url");
}
and I have it configured like that:
@Configuration
public class MyConfiguration {
@Bean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public Installation createInstallation(String url) {
return new Installation(url);
}
}
But when I start my application I get the following exception:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method createInstallation in com.mycompany.MyConfiguration required a bean of type 'java.lang.String' that could not be found.
Action:
Consider defining a bean of type 'java.lang.String' in your configuration.
Given that this is occurring at startup it seems like Spring tries to autowire this bean at startup. However, my understand is that a a bean of scope SCOPE_PROTOTYPE should not be autowire at runtime, as I want to create the beans during runtime with different parameters.