Exercise 4

This commit is contained in:
Moritz Halbritter 2025-05-13 14:55:00 +02:00
parent 1e2e977dda
commit c469b2a940
3 changed files with 19 additions and 0 deletions

View File

@ -19,6 +19,10 @@
<groupId>com.workshop</groupId>
<artifactId>library-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -24,6 +24,11 @@
<artifactId>library-stdout</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-slf4j</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>

View File

@ -1,11 +1,13 @@
package com.workshop.magic.config;
import com.workshop.magic.service.GreetingService;
import com.workshop.magic.service.slf4j.LoggerGreetingService;
import com.workshop.magic.service.stdout.StdOutGreetingService;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
@AutoConfiguration
@ -15,8 +17,16 @@ public class GreetingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(StdOutGreetingService.class)
@ConditionalOnMissingClass("com.workshop.magic.service.slf4j.LoggerGreetingService")
GreetingService stdOutGreetingService() {
return new StdOutGreetingService();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(LoggerGreetingService.class)
GreetingService slf4jGreetingService() {
return new LoggerGreetingService();
}
}