Java Version - 11 Spring Boot Version - 2.6.4 Tomcat Version - 9.0.59
Starting with Spring Boot version 2.6.4 environment prepared method is not getting called when spring boot application is deployed as a war to external tomcat server.
Attached is the project to simulate behavior along with snapshots showing difference between 2.6.3 and 2.6.4
Change version of Spring Boot in build.gradle file to reproduce.
Comment From: wilkinsona
Thanks for the report. Unfortunately, the sample that you have provided does not reproduce the behaviour that you have described. With 2.6.4, I see your EnvironmentPostProcessor
being called:
02-Mar-2022 09:53:15.651 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/Users/awilkinson/dev/temp/gh-30026/apache-tomcat-9.0.59/webapps/ROOT.war]
02-Mar-2022 09:53:16.962 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
********************
ENVIRONMENT_PREPARED
********************
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.4)
2022-03-02 09:53:17.632 INFO 57611 --- [ main] com.example.demo.ServletInitializer : Starting ServletInitializer using Java 11.0.10 on wilkinsona-a01.vmware.com with PID 57611 (/Users/awilkinson/dev/temp/gh-30026/apache-tomcat-9.0.59/webapps/ROOT/WEB-INF/classes started by awilkinson in /Users/awilkinson/dev/temp/gh-30026)
2022-03-02 09:53:17.635 INFO 57611 --- [ main] com.example.demo.ServletInitializer : No active profile set, falling back to 1 default profile: "default"
2022-03-02 09:53:18.383 INFO 57611 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 690 ms
2022-03-02 09:53:18.889 INFO 57611 --- [ main] com.example.demo.ServletInitializer : Started ServletInitializer in 1.73 seconds (JVM running for 4.378)
02-Mar-2022 09:53:18.914 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/Users/awilkinson/dev/temp/gh-30026/apache-tomcat-9.0.59/webapps/ROOT.war] has finished in [3,262] ms
02-Mar-2022 09:53:18.916 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
02-Mar-2022 09:53:18.924 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [3335] milliseconds
Can you please describe how to use your sample to reproduce the problem?
Comment From: gurpreetsingh85
@wilkinsona Thank you for quick response.
I am attaching another sample project. This time i have disabled traditional war task.
Running ./gradlew clean build
should only build boot war and deploying it to external tomcat should reproduce this issue.
Comment From: wilkinsona
Thanks. I've reproduced the problem now. It's a regression caused by the changes for https://github.com/spring-projects/spring-boot/issues/28562. The spring.factories
file is being packaged in META-INF/spring.factories
rather than in WEB-INF/classes/META-INF/spring.factories
which means it can't be found when deployed as a war file.
Comment From: wilkinsona
The Maven repackaging only applies its special handling of META-INF
for a RepackagingLayout
. org.springframework.boot.loader.tools.Layouts.War
is not a RepackagingLayout
so war files are not affected. The changes for #28562 need to be modified so that they only apply to jars.