Is there a way to autwire bean able?
The following example. We have 2 implementation of FileManager. One implementation option should be initialized depending on the property platform. Properties are processed through Archaius.
@Component public class AwsPlatformCondition implements Condition { @Autowired private ArchaiusProperties archaiusProperties; @Override public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { return "aws".equalsIgnoreCase(archaiusProperties.getStringProperty(PropertiesMapper.PLATFORM)); } }
.
@Component public class StandardPlatformCondition implements Condition { @Autowired private ArchaiusProperties archaiusProperties; @Override public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { return "standard".equalsIgnoreCase(archaiusProperties.getStringProperty(PropertiesMapper.PLATFORM)); } }
.
@Component @Conditional(AwsPlatformCondition.class) public class AS3FileManager implements FileManager { ... }
.
@Component @Conditional(StandardPlatformCondition.class) public class NativeFileManager implements FileManager { ... }
This code does not work. The main reason is that the ArchaiusProperties bean is not initialized when the condition is met. Is there a way to initialize an ArchaiusProperties bean before using it in state?
source share