From b56ba8b97dc8037cac078f50d2c7784ffb1fbed5 Mon Sep 17 00:00:00 2001 From: Ralf Ueberfuhr Date: Thu, 21 Dec 2023 11:15:06 +0100 Subject: [PATCH] introduce profiles --- .../schulung/spring/blog/domain/BlogPostInitializer.java | 2 ++ src/main/resources/application-default.yml | 1 + src/main/resources/application-dev.yml | 3 +++ src/main/resources/application.yml | 3 --- .../sample/schulung/spring/blog/boundary/BlogPostApiTests.java | 2 ++ 5 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/application-default.yml create mode 100644 src/main/resources/application-dev.yml diff --git a/src/main/java/de/sample/schulung/spring/blog/domain/BlogPostInitializer.java b/src/main/java/de/sample/schulung/spring/blog/domain/BlogPostInitializer.java index bbd4e49..872dd08 100644 --- a/src/main/java/de/sample/schulung/spring/blog/domain/BlogPostInitializer.java +++ b/src/main/java/de/sample/schulung/spring/blog/domain/BlogPostInitializer.java @@ -1,12 +1,14 @@ package de.sample.schulung.spring.blog.domain; import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Profile; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor +@Profile("!no-initialization") public class BlogPostInitializer { private final BlogPostService service; diff --git a/src/main/resources/application-default.yml b/src/main/resources/application-default.yml new file mode 100644 index 0000000..48d7710 --- /dev/null +++ b/src/main/resources/application-default.yml @@ -0,0 +1 @@ +# Einstellungen, falls KEIN (anderes) Profil aktiviert ist diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..0e2a6b4 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,3 @@ +logging: + level: + de.sample.schulung.spring.blog.domain.BlogPostEventLogger: debug diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1b0d8dd..626ada3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,2 @@ server: port: ${SERVER_PORT:9080} -logging: - level: - de.sample.schulung.spring.blog.domain.BlogPostEventLogger: debug diff --git a/src/test/java/de/sample/schulung/spring/blog/boundary/BlogPostApiTests.java b/src/test/java/de/sample/schulung/spring/blog/boundary/BlogPostApiTests.java index d6a8fa1..39f0a8a 100644 --- a/src/test/java/de/sample/schulung/spring/blog/boundary/BlogPostApiTests.java +++ b/src/test/java/de/sample/schulung/spring/blog/boundary/BlogPostApiTests.java @@ -6,6 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import static org.assertj.core.api.Assertions.assertThat; @@ -15,6 +16,7 @@ @SpringBootTest @AutoConfigureMockMvc +@ActiveProfiles("no-initialization") class BlogPostApiTests { @Autowired