我需要添加一个接口的多个实现,并且应该根据配置文件选择其中一个。
例如
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。
拉丁的传说
阿晨1998
富国沪深
随时随地看视频慕课网APP
相关分类