Exercise 2

This commit is contained in:
Moritz Halbritter 2025-05-13 14:48:32 +02:00
parent bd98dab588
commit 7ccc2fb465
5 changed files with 48 additions and 3 deletions

View File

@ -15,10 +15,18 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-api</artifactId>
</dependency>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-stdout</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>

View File

@ -2,9 +2,7 @@ package com.workshop.magic.app;
import com.workshop.magic.service.AbstractGreetingService;
import org.springframework.stereotype.Service;
@Service
//@Service
class MyGreetingService extends AbstractGreetingService {
@Override

View File

@ -13,4 +13,20 @@
<artifactId>library-autoconfigure</artifactId>
<dependencies>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.workshop</groupId>
<artifactId>library-stdout</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,22 @@
package com.workshop.magic.config;
import com.workshop.magic.service.GreetingService;
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.context.annotation.Bean;
@AutoConfiguration
@ConditionalOnClass(GreetingService.class)
public class GreetingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(StdOutGreetingService.class)
GreetingService stdOutGreetingService() {
return new StdOutGreetingService();
}
}

View File

@ -0,0 +1 @@
com.workshop.magic.config.GreetingAutoConfiguration