【发布时间】:2017-01-18 09:58:16
【问题描述】:
例如,我有很多配置文件,“dev”、“prod”、“test”等。
interface A
@Component
class DefaultImpl implements A
@Profile("test")
@Component
class TestImpl implements A
我只希望 TestImpl 用于配置文件“test”,而 DefaultImpl 用于所有其他配置文件。
更新: 为什么@Profile("default") 对我不起作用:
我有两个测试配置文件,即“test1”和“test2”
我在配置文件“test1”中提供了不同的实现:
@Profile("default")
class DefaultImpl extends A
@Profile("test1")
class Test1Impl extends A
现在当我@ActivateProfile("test2") 时,它不会选择 DefaultImpl
但是,如果我不设置配置文件,如下所示:
class DefaultImpl extends A
@Profile("test1")
class Test1Impl extends A
profile "test2" 最终会有两个 bean 并且不知道要连接哪个。
目前,只有这个可行:
@Profile("test2", "prod", ....)
class DefaultImpl extends A
@Profile("test1")
class Test1Impl extends A
除了在 DefaultImpl 中添加所有其他配置文件名称之外,我还能做什么?
【问题讨论】: