Why not simply define a new Bean
in your ApplicationContext
by using Class.forName()
from the @Value
injected into the @Configuration
?
So something like this:
@Configuration
public class MyConfiguration
{
@Value("${app.serviceClass}")
private String serviceClassName;
@Bean
public Object myService()
{
return Class.forName(serviceClassName).newInstance();
}
}
EDIT by sjngm (for better readability than in the comment):
@Bean
public MyInterface myService()
{
Class<?> serviceClass = Class.forName(serviceClassName);
MyInterface service = MyInterface.class.cast(serviceClass.newInstance());
return service;
}