0

First time using Profiles and need help. I have an abstract base class (DecisionManagementRuleExecutor) that gets its dependency (RuleHandler) wired through annotation.

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

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

   @Autowired
   RuleHandler ruleHandler;

When I run with 'itest' profile, I want 'ITestRuleHandler' a child of 'RuleHandler' to be wired. Where 'ItestRuleHandler' is

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

I see that in the logs that active profile is 'itest'

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

I am pasting the log for the wiring

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'

Edit: Changed the 'RuleHandler' as an interface and now I am getting this error:

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

1 Answers1

0

To make the implementation ITestRuleHandler available for the itest profile, you need to declare your class as:

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

@ActiveProfiles activates one or more profiles, not expose a component for a profile. This should be applied to one of the test (or consuming) classes to activate a profile for testing (or consumption).

manish
  • 19,695
  • 5
  • 67
  • 91