I need to add multiple implementations of an interface and one of them should be picked up based on profile.
For e.g.
interface Test{
public void test();
}
@Service
@Profile("local")
class Service1 implements Test{
public void test(){
}
}
@Service
class Service2 implements Test{
public void test(){
}
}
@SpringBootApplication
public class Application {
private final Test test;
public Application(final Test test) {
this.test = test;
}
@PostConstruct
public void setup() {
test.test();
}
}
My intention is when I use -Dspring.profiles.active=local then Service1 should be called or else service2 should be called but I am getting an exception that the bean for Test is missing.