spring - 如何在 Kotlin 中排除多个 Spring 配置文件?
问题描述
我使用了这个结构:
@Profile("!test")
好的,但我需要设置不要将此 bean 与多个配置文件一起使用。只要 value 字段是 String[],我写了这个:
@Profile(value = ["!local", "!test"])
并得到这个例外:
引起:org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有“ru.example.service.AuthenticationService”类型的合格bean可用:预期单个匹配bean但找到2:testAuthenticationService,springAuthenticationService
正如我们所看到的,上面的结构不起作用。如何在我的情况下设置个人资料?
解决方案
@Profile(value = ["!local", "!test"])
相当于 `@Profile("!local | !test") 意味着只排除本地和测试的 bean。
您需要的是 `@Profile("!local & !test") 来排除本地或测试。
这是德摩根定律的一个例子!(foo | bar) == !foo & !bar
,但你有!foo | !bar == !(foo & bar)
。
推荐阅读
- google-cloud-platform - 设置 Google Query 时的最佳安全做法是什么?
- reactjs - 在 React 美丽的 dnd 中渲染一个组件
- ruby-on-rails - 如何解决 nginx 找不到 puma?
- javascript - 处理多个对象
- javascript - 写这个的正确方法是什么?需要替换一个switch语句
- angular - 子项角度路由中的不同 RoleGuard
- java - 在 Linux 中使用 7zip 将 ISO 提取到位置
- html - 阻止表格单元格重叠 HTML CSS
- r - 在 DataFrame 中插入向量
- jquery - 带有锁定列的 Kendo Grid 偏移未锁定的列对齐垂直和水平