As the question states, my following code uses some properties to startup some camel routes with spring boot. But this has to happen conditionally on the camel routes class by the use of an env variable.
@Configuration
public class SomeCondition implements Condition {
private final Properties properties;
public SomeCondition(Properties properties) {
this.properties = properties;
}
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return properties.isEnableData();
}
}
But when trying to start or run some tests, I get the error:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [xxx.in.annotation.SomeCondition]: No default constructor found; nested exception is java.lang.NoSuchMethodException: xxx.in.annotation.SomeCondition.<init>()
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.context.annotation.ConditionEvaluator.getCondition(ConditionEvaluator.java:125)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:96)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:88)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:71)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isConditionMatch(ClassPathScanningCandidateComponentProvider.java:513)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:496)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430)
... 88 more
Caused by: java.lang.NoSuchMethodException:
xxxx.in.annotation.SomeCondition.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3349)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 95 more
Is there any way to autowire or to inject something in a condition?