BAEL-4871 Spring Conditional Annotations

This commit is contained in:
majewsk6 2021-05-16 20:16:33 +02:00
parent 9d5b3fcedb
commit 4d08dcace0
8 changed files with 16 additions and 17 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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 {
}