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.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.ConditionContext;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package java.com.baeldung.annotations.conditional;
|
||||
package com.baeldung.annotations.conditional;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
|
@ -10,6 +10,6 @@ public class IsWindowsCondition implements Condition {
|
|||
|
||||
@Override
|
||||
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.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
@ -9,6 +9,6 @@ public class Java8Condition implements Condition {
|
|||
|
||||
@Override
|
||||
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.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.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.ConditionContext;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
|
@ -9,6 +9,6 @@ public class Java9Condition implements Condition {
|
|||
|
||||
@Override
|
||||
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.ConditionalOnJava;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.system.JavaVersion;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Conditional(IsDevEnvCondition.class)
|
||||
@Conditional({IsDevEnvCondition.class, IsWindowsCondition.class, Java8Condition.class})
|
||||
@ConditionalOnProperty(
|
||||
value = "logging.enabled",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnExpression("${logging.enabled:true} and ${logging.level:DEBUG}")
|
||||
@ConditionalOnJava(ConditionalOnJava.JavaVersion.EIGHT)
|
||||
@Conditional(IsWindowsCondition.class)
|
||||
@Conditional(Java8Condition.class)
|
||||
@ConditionalOnJava(JavaVersion.EIGHT)
|
||||
public class LoggingService {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue