diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java index b7afbc711f2..be5c7d0e7c7 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactory.java @@ -10,6 +10,7 @@ import tech.jhipster.lite.module.domain.javadependency.JavaDependency; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope; import tech.jhipster.lite.module.domain.javadependency.JavaDependencyType; +import tech.jhipster.lite.module.domain.javaproperties.PropertiesBlockComment; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; import tech.jhipster.lite.module.domain.replacement.TextNeedleBeforeReplacer; import tech.jhipster.lite.shared.error.domain.Assert; @@ -21,7 +22,6 @@ public class SpringBootCoreModuleFactory { private static final JHipsterSource TEST_SOURCE = SOURCE.append("test"); private static final GroupId SRPING_BOOT_GROUP = groupId("org.springframework.boot"); - private static final String APPLICATION_PROPERTIES = "application.properties"; private static final String JUNIT_GROUP = "org.junit.jupiter"; private static final String MOCKITO_GROUP = "org.mockito"; @@ -32,9 +32,7 @@ public class SpringBootCoreModuleFactory { ); private static final JHipsterDestination MAIN_RESOURCE_DESTINATION = to("src/main/resources"); - private static final JHipsterDestination MAIN_CONFIG_DESTINATION = MAIN_RESOURCE_DESTINATION.append("config"); private static final JHipsterDestination TEST_RESOURCES_DESTINATION = to("src/test/resources"); - private static final JHipsterDestination TEST_CONFIG_DESTINATION = TEST_RESOURCES_DESTINATION.append("config"); public JHipsterModule buildModule(JHipsterModuleProperties properties) { Assert.notNull("properties", properties); @@ -43,6 +41,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { String packagePath = properties.packagePath(); JHipsterDestination testDestination = toSrcTestJava().append(packagePath); String fullyQualifiedMainClass = properties.basePackage().get() + "." + baseName + "App"; + String basePackageLoggingLevel = "logging.level.%s".formatted(properties.basePackage().get()); //@formatter:off return moduleBuilder(properties) @@ -68,13 +67,26 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { .add(MAIN_SOURCE.template("MainApp.java"), toSrcMainJava().append(packagePath).append(baseName + "App.java")) .add(MAIN_SOURCE.template("ApplicationStartupTraces.java"), toSrcMainJava().append(packagePath).append("ApplicationStartupTraces.java")) .add(TEST_SOURCE.template("IntegrationTest.java"), testDestination.append("IntegrationTest.java")) - .add(MAIN_SOURCE.template(APPLICATION_PROPERTIES), MAIN_CONFIG_DESTINATION.append(APPLICATION_PROPERTIES)) - .add(MAIN_SOURCE.template("application-local.properties"), MAIN_CONFIG_DESTINATION.append("application-local.properties")) - .add(TEST_SOURCE.template("application-test.properties"), TEST_CONFIG_DESTINATION.append("application-test.properties")) .add(MAIN_SOURCE.template("logback-spring.xml"), MAIN_RESOURCE_DESTINATION.append("logback-spring.xml")) .add(TEST_SOURCE.template("logback.xml"), TEST_RESOURCES_DESTINATION.append("logback.xml")) .add(TEST_SOURCE.template("ApplicationStartupTracesTest.java"), toSrcTestJava().append(packagePath).append("ApplicationStartupTracesTest.java")) .and() + .springMainProperties() + .set(propertyKey("spring.application.name"), propertyValue(baseName)) + .set(propertyKey(basePackageLoggingLevel), propertyValue("INFO")) + .and() + .springLocalProperties() + .set(propertyKey(basePackageLoggingLevel), propertyValue("DEBUG")) + .and() + .springTestProperties() + .set(propertyKey("spring.main.banner-mode"), propertyValue("off")) + .set(PropertiesBlockComment.builder() + .comment(comment("Logging configuration")) + .add(propertyKey(basePackageLoggingLevel), propertyValue("OFF")) + .add(propertyKey("logging.config"), propertyValue("classpath:logback.xml")) + .build() + ) + .and() .optionalReplacements() .in(path("pom.xml")) .add(DEFAULT_GOAL_REPLACER, properties.indentation().times(2) + "spring-boot:run") diff --git a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java index 3fd8f48de7b..82599fa02c3 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java +++ b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModule.java @@ -506,6 +506,10 @@ public JHipsterModuleSpringPropertiesBuilder springMainProperties() { return springMainProperties(SpringProfile.DEFAULT); } + public JHipsterModuleSpringPropertiesBuilder springLocalProperties() { + return springMainProperties(SpringProfile.LOCAL); + } + public JHipsterModuleSpringPropertiesBuilder springMainBootstrapProperties() { return springMainBootstrapProperties(SpringProfile.DEFAULT); } diff --git a/src/main/java/tech/jhipster/lite/module/domain/javaproperties/SpringProfile.java b/src/main/java/tech/jhipster/lite/module/domain/javaproperties/SpringProfile.java index 9f0e21cd758..5575ba22812 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/javaproperties/SpringProfile.java +++ b/src/main/java/tech/jhipster/lite/module/domain/javaproperties/SpringProfile.java @@ -4,6 +4,7 @@ public record SpringProfile(String profile) { public static final SpringProfile DEFAULT = new SpringProfile(null); + public static final SpringProfile LOCAL = new SpringProfile("local"); public static final SpringProfile TEST = new SpringProfile("test"); public String get() { diff --git a/src/main/resources/generator/server/springboot/core/main/application-local.properties.mustache b/src/main/resources/generator/server/springboot/core/main/application-local.properties.mustache deleted file mode 100644 index 6361fd14fcf..00000000000 --- a/src/main/resources/generator/server/springboot/core/main/application-local.properties.mustache +++ /dev/null @@ -1,7 +0,0 @@ -#==================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -#==================================================================== - -logging.level.{{packageName}}=DEBUG diff --git a/src/main/resources/generator/server/springboot/core/main/application.properties.mustache b/src/main/resources/generator/server/springboot/core/main/application.properties.mustache deleted file mode 100644 index 49a4701e45b..00000000000 --- a/src/main/resources/generator/server/springboot/core/main/application.properties.mustache +++ /dev/null @@ -1,8 +0,0 @@ -#==================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -#==================================================================== - -spring.application.name={{baseName}} -logging.level.{{packageName}}=INFO diff --git a/src/main/resources/generator/server/springboot/core/test/application-test.properties.mustache b/src/main/resources/generator/server/springboot/core/test/application-test.properties.mustache deleted file mode 100644 index 5599d61ef33..00000000000 --- a/src/main/resources/generator/server/springboot/core/test/application-test.properties.mustache +++ /dev/null @@ -1,11 +0,0 @@ -#==================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -#==================================================================== - -spring.main.banner-mode=off - -# Logging configuration -logging.level.{{packageName}}=OFF -logging.config=classpath:logback.xml diff --git a/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java index 65ce8fa1fa1..df0e89f38eb 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/springboot/core/domain/SpringBootCoreModuleFactoryTest.java @@ -141,11 +141,18 @@ void shouldBuildModuleOnProjectWithoutDefaultGoal() { .and() .hasFiles("src/main/java/com/jhipster/test/ApplicationStartupTraces.java") .hasPrefixedFiles("src/test/java/com/jhipster/test", "ApplicationStartupTracesTest.java", "IntegrationTest.java") - .hasFiles( - "src/main/resources/config/application.properties", - "src/main/resources/config/application-local.properties", - "src/test/resources/config/application-test.properties" - ) + .hasFile("src/main/resources/config/application.properties") + .containing("spring.application.name=Myapp") + .containing("logging.level.com.jhipster.test=INFO") + .and() + .hasFile("src/main/resources/config/application-local.properties") + .containing("logging.level.com.jhipster.test=DEBUG") + .and() + .hasFile("src/test/resources/config/application-test.properties") + .containing("spring.main.banner-mode=off") + .containing("logging.level.com.jhipster.test=OFF") + .containing("logging.config=classpath:logback.xml") + .and() .hasFiles("src/test/resources/logback.xml", "src/main/resources/logback-spring.xml"); }