spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.58k stars 40.55k forks source link

spring.aot.enabled=true breaks logback from loading #41441

Closed javapapo closed 2 months ago

javapapo commented 2 months ago

-SpringBoot 3.3.1 , Java 21, AWS correto. SpringBoot microservice, jar packaging.

-Spring AOT compilation enabled

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>process-aot</id>
                        <goals>
                            <goal>process-aot</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

java -Dlogging.config=classpath:logback-xx.xml -Dspring.aot.enabled=true -jar ./target/demo-service.jar

When spring.aot is enabled - logback is not loaded at all. When you dont enable aot then logback is picked

javapapo commented 2 months ago

image

scottfrederick commented 2 months ago

When spring.aot is enabled - logback is not loaded at all.

Do you mean that the Logback configuration is not loaded from -Dlogging.config=classpath:logback-xx.xml? If so, then this is the expected behavior.

Logback is supported, including XML configuration. XML configuration is loaded at build time during AOT processing and translated into a fixed, native-friendly format. As a result, loading different XML configuration at runtime is not supported.

If overriding the default Logback config at runtime with AOT isn't the problem you are trying to describe, then please provide a complete example that demonstrates the problem that we can run ourselves and we can re-open the issue.

javapapo commented 2 months ago

Thanks , most probably missed that - the reason I am using the logging.config property is because I want to have a different logback config per Spring profile (dev, prod).

So what is the recommended way to do it? Have a single logback-spring.xml with profiles inside?

@scottfrederick