This commit is contained in:
Moritz Halbritter 2025-05-13 16:06:09 +02:00
parent 7626d5ccb3
commit fa77e2057c
4 changed files with 44 additions and 6 deletions

View File

@ -28,6 +28,11 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -38,5 +38,27 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -22,7 +22,7 @@ public class GreetingAutoConfiguration {
@ConditionalOnClass(StdOutGreetingService.class) @ConditionalOnClass(StdOutGreetingService.class)
@ConditionalOnProperty(name = "workshop.greeting.type", havingValue = "stdout", matchIfMissing = true) @ConditionalOnProperty(name = "workshop.greeting.type", havingValue = "stdout", matchIfMissing = true)
GreetingService stdOutGreetingService(GreetingProperties properties) { GreetingService stdOutGreetingService(GreetingProperties properties) {
return new StdOutGreetingService(properties.getText()); return new StdOutGreetingService(properties.getPrefix());
} }
@Bean @Bean
@ -30,7 +30,7 @@ public class GreetingAutoConfiguration {
@ConditionalOnClass(LoggerGreetingService.class) @ConditionalOnClass(LoggerGreetingService.class)
@ConditionalOnProperty(name = "workshop.greeting.type", havingValue = "logger") @ConditionalOnProperty(name = "workshop.greeting.type", havingValue = "logger")
GreetingService slf4jGreetingService(GreetingProperties properties) { GreetingService slf4jGreetingService(GreetingProperties properties) {
return new LoggerGreetingService(properties.getText()); return new LoggerGreetingService(properties.getPrefix());
} }
@Bean @Bean
@ -38,6 +38,6 @@ public class GreetingAutoConfiguration {
@MyCustomCondition @MyCustomCondition
@ConditionalOnClass(BeepGreetingService.class) @ConditionalOnClass(BeepGreetingService.class)
GreetingService beepGreetingService(GreetingProperties properties) { GreetingService beepGreetingService(GreetingProperties properties) {
return new BeepGreetingService(properties.getText()); return new BeepGreetingService(properties.getPrefix());
} }
} }

View File

@ -1,18 +1,21 @@
package com.workshop.magic.config; package com.workshop.magic.config;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
@ConfigurationProperties(prefix = "workshop.greeting") @ConfigurationProperties(prefix = "workshop.greeting")
public class GreetingProperties { public class GreetingProperties {
private String text = "Hello";
private Type type = Type.STDOUT; private Type type = Type.STDOUT;
private String prefix = "Hello";
@DeprecatedConfigurationProperty(replacement = "workshop.greeting.prefix")
@Deprecated
public String getText() { public String getText() {
return this.text; return this.prefix;
} }
public void setText(String text) { public void setText(String text) {
this.text = text; this.prefix = text;
} }
public Type getType() { public Type getType() {
@ -23,6 +26,14 @@ public class GreetingProperties {
this.type = type; this.type = type;
} }
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public enum Type { public enum Type {
STDOUT, STDOUT,
LOGGER, LOGGER,