我需要添加多个接口实现,其中一个应该根据配置文件进行选择。
例如:
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();
}
}
我的意图是在使用-Dspring.profiles.active=local时调用Service1,否则调用service2,但我收到了一个异常错误,提示缺少Test的bean。