无法使用 ActiveProfile 注释进行连接

Unable to wire using ActiveProfile annotation

第一次使用个人资料,需要帮助。 我有一个抽象基础 class (DecisionManagementRuleExecutor),它通过注释获取其依赖项 (RuleHandler)。

    @Component
    public class RuleHandler {......

   public abstract class DecisionManagementRuleExecutor<M extends PersistentEntity,T extends Response> implements RuleExecutor<M,T>{

   @Autowired
   RuleHandler ruleHandler;

当我 运行 使用 'itest' 配置文件时,我希望 'ITestRuleHandler' 连接 'RuleHandler' 的 child。 其中 'ItestRuleHandler' 是

    @Component
    @ActiveProfiles(value = "itest")
    public class ITestRuleHandler extends RuleHandler {

我在日志中看到活动配置文件是 'itest'

    System.getProperty("spring.profiles.active")

我正在粘贴接线日志

Processing injected element of bean 'vendorServiceRuleExecutor': AutowiredFieldElement for c.a.p.d.RuleHandler c.a.p.d.s.DecisionManagementRuleExecutor.ruleHandler Returning cached instance of singleton bean 'ITestRuleHandler' Creating shared instance of singleton bean 'ruleHandler' Creating instance of bean 'ruleHandler' Eagerly caching bean 'ruleHandler' to allow for resolving potential circular references Finished creating instance of bean 'ruleHandler' Autowiring by type from bean name 'vendorServiceRuleExecutor' to bean named 'ruleHandler' Finished creating instance of bean 'vendorServiceRuleExecutor'

编辑: 将 'RuleHandler' 更改为接口,现在我收到此错误:

  No qualifying bean of type [c.a.p.d.RuleHandler] is defined: expected single matching bean but found 2: ITestRuleHandler,iTestRuleHandler

要使实施 ITestRuleHandler 可用于 itest 配置文件,您需要将 class 声明为:

@Component
@Profile("itest")
public class ITestRuleHandler extends RuleHandler

@ActiveProfiles 激活一个或多个配置文件,而不是公开配置文件的组件。这应该应用于测试(或消费)之一 classes 以激活用于测试(或消费)的配置文件。