BAEL-4871 Spring Conditional Annotations
This commit is contained in:
parent
9d5b3fcedb
commit
4d08dcace0
|
@ -1,4 +1,4 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
|
@ -10,6 +10,6 @@ public class IsWindowsCondition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
return SystemUtils.IS_OS_WINDOWS;;
|
return SystemUtils.IS_OS_WINDOWS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava;
|
import org.springframework.boot.system.JavaVersion;
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
@ -9,6 +9,6 @@ public class Java8Condition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
return ConditionalOnJava.JavaVersion.getJavaVersion().equals(ConditionalOnJava.JavaVersion.EIGHT);
|
return JavaVersion.getJavaVersion().equals(JavaVersion.EIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava;
|
import org.springframework.boot.system.JavaVersion;
|
||||||
import org.springframework.context.annotation.Condition;
|
import org.springframework.context.annotation.Condition;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
@ -9,6 +9,6 @@ public class Java9Condition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||||
return ConditionalOnJava.JavaVersion.getJavaVersion().equals(ConditionalOnJava.JavaVersion.NINE);
|
return JavaVersion.getJavaVersion().equals(JavaVersion.NINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
package java.com.baeldung.annotations.conditional;
|
package com.baeldung.annotations.conditional;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.system.JavaVersion;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Conditional(IsDevEnvCondition.class)
|
@Conditional({IsDevEnvCondition.class, IsWindowsCondition.class, Java8Condition.class})
|
||||||
@ConditionalOnProperty(
|
@ConditionalOnProperty(
|
||||||
value = "logging.enabled",
|
value = "logging.enabled",
|
||||||
havingValue = "true",
|
havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
@ConditionalOnExpression("${logging.enabled:true} and ${logging.level:DEBUG}")
|
@ConditionalOnExpression("${logging.enabled:true} and ${logging.level:DEBUG}")
|
||||||
@ConditionalOnJava(ConditionalOnJava.JavaVersion.EIGHT)
|
@ConditionalOnJava(JavaVersion.EIGHT)
|
||||||
@Conditional(IsWindowsCondition.class)
|
|
||||||
@Conditional(Java8Condition.class)
|
|
||||||
public class LoggingService {
|
public class LoggingService {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue