I\'m using Spring Beans with annotations and I need to choose different implementation at runtime.
@Service
public class MyService {
public void test(){..
You can move the bean injection into the configuration, as:
@Configuration
public class AppConfig {
@Bean
public MyService getMyService() {
if(windows) return new MyServiceWin();
else return new MyServiceLnx();
}
}
Alternatively, you may use profiles windows
and linux
, then annotate your service implementations with the @Profile
annotation, like @Profile("linux")
or @Profile("windows")
, and provide one of this profiles for your application.