【发布时间】:2021-08-30 14:01:42
【问题描述】:
我使用了这个结构:
@Profile("!test")
好的,但我需要设置不要将此 bean 与多个配置文件一起使用。只要 value 字段是 String[],我是这样写的:
@Profile(value = ["!local", "!test"])
并得到这个异常:
原因: org.springframework.beans.factory.NoUniqueBeanDefinitionException: 否 'ru.example.service.AuthenticationService' 类型的限定 bean 可用:预期单个匹配 bean,但找到 2: testAuthenticationService,springAuthenticationService
如我们所见,上面的构造不起作用。在我的情况下如何设置个人资料?
【问题讨论】:
-
您是否将
@Profile("test")放在 testAuthenticationService bean 或 Autowired ctor 上? -
投入使用。
-
我想我知道问题出在哪里了,你可以试试
@Profile("!test & !local") -
我的理论是您有 2 个配置文件“!local”(包括测试)和“!test”(包括本地),因此您需要有一个排除这两个配置文件的单个配置文件
-
哇!有用!请在下面对我的问题做出正确的回答,我会接受。
标签: spring kotlin spring-profiles