【发布时间】:2020-01-06 16:21:14
【问题描述】:
我将 spring 从版本 2.1.1 升级到 2.2.0 。 从那时起,当我启动我的应用程序时,我遇到了以下错误: 原因:org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有可用的“ParentService”类型的合格 bean:预期的单个匹配 bean,但找到了 2:MasterService,SlaveService。
ParentService 是一个接口:
public interface ParentService{
..
}
主服务:
@Service
@MasterProfile
public class MasterService implements ParentService{
.....
}
从服务:
@Service
@SlaveProfile
public class SlaveService implements ParentService{
.....
}
MasterProfile 注释:
@Profile("MASTER")
public @interface MasterProfile {
}
从属配置文件:
@Profile("SLAVE")
public @interface SlaveProfile{
}
我将带有以下标志的配置文件传递给我的应用程序:
-Dspring.profiles.include=MASTER
根据Spring 2.2 release notes,他们做了一些改动,并且在maven中默认启用了fork。因此,传递参数的唯一方法是使用参数 -Dspring-boot.run.jvmArguments 。我使用了-Dspring-boot.run.jvmArguments=-Dspring.profiles.include=MASTER,但仍然失败..
【问题讨论】:
-
但我有 @Profile 注释,应该可以帮助 spring 确定要自动写入的 bean。正如我所提到的,在 2.1.1 版本中它起作用了。
-
它们是我自己的注解,只是上面带有@profile注解的简单接口
-
与 MasterProfile 相同,只是名称不同。将其添加到主帖
-
"以下配置文件处于活动状态:test,native。"这意味着它没有得到配置文件(主或从)。与将配置文件传递给 spring 的方式有关的东西
-
但如果我想激活多个配置文件?
标签: java spring spring-boot