Spring boot - Unsupported config data location 'optional:file:./config/*/' - spring-boot

We are migrating a spring boot application from 2.2.4 to 2.4.3
The application can be run with inbuilt tomcat / Tomcat war deployment.
Environment: Windows Azul Java 11 (Zulu 11) and Tomcat 9.0.33
If I run the code with my Netbeans linked tomcat, it works fine.
If I deploy the generated war directly in the same standalone tomcat, it throws the following error.
SEVERE [main] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [D:\apache-tomcat-9.0.33-without port - rest.war]
java.lang.IllegalStateException: Error starting child
................................................................
................................................................
Caused by: org.springframework.boot.context.config.UnsupportedConfigDataLocationException: Unsupported config data location 'optional:file:./config/*/'
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:110)
On reading through the Spring document, it was mentioned that By default, Spring Boot includes config/*/ in the default search locations. Ref: https://docs.spring.io/spring-boot/docs/2.4.0-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-files-wildcards
I further debugged with spring boot source and spring core source and identified that there is a mismatch in the classloader that happens that was the cause of this exception.
SpringFactoriesLoader is the class that gets loaded by ParallelWebAppClassLoader in NB linked tomcat and by URLClassLoader in standalone tomcat.
Ref: Line No 129 at https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java#L129
The cache at Line 136 has the config classes loaded by ParallelWebAppClassLoader, but not by the URLlassLoader. So the 2 resolvers - ConfigTreeConfigDataLocationResolver, StandardConfigDataLocationResolver in boot v2.4.3 are not getting identified when it tries to retrieve with the key URLlassLoader (Line 136).
Not sure whether this is an issue with Springboot / SpringCore / Tomcat / any new configuration to be added as a part of our upgrade.
Note: Our application.properties has spring.servlet.multipart related properties only.

"./" is not getting resolved in standalone tomcat.
Try using classpath:application.properties , or classpath:config/* -- this would require props inside war.
or absolute path of file:/var/myapp/config/*. Since tomcat is in D:, you may create a folder d:/var/myapp/config/.
Note that within spring you can ignore "d:" and just mention "/var/myapp/config/*", so, in-case tomcat is in "x:" your code need not change.

This was an issue in Spring boot.
Updating to version 2.4.6 will solve this issue.

Related

Found 2 files with the path - migration liquibase from 3.7.0 to 4.15.0

I am migrating a spring boot app from 2.1.8.RELEASE to 2.7.7.
I am getting a liquibase error when running integrations tests with h2.
Caused by: java.io.IOException: Found 2 files with the path '../sqlFiles/file_name.sql'
- file:/C:/yy/yy/target/test-classes/config/liquibase/sqlFiles/file_name.sql
- file:/C:/yy/yy/target/classes/config/liquibase/sqlFiles/file_name.sql
I tried spring.liquibase.duplicateFileMode=WARN >>> does not work.
Liquibase-maven-plugin is excluded from test context, but I still get this error ?

Failed to bind properties under 'spring.datasource.oracleucp.s-s-l-context.provider'

I ma facing the issue while migrating the hava 11 to 17 and spring boot to 3.0 and spring web 6.
APPLICATION FAILED TO START
Description:
Failed to bind properties under 'spring.datasource.oracleucp.s-s-l-context.provider' to java.security.Provider:
Reason: java.lang.NoSuchMethodException: java.security.Provider.<init>()
Action:
Update your application's configuration
This seems that may be you have not added the following properties in application.properties file add also your may be facing this issue because in spring security version which you are using with sring-3 is not compatible with spring-6 for more information read this https://spring.io/blog/2022/11/21/spring-security-5-8-and-6-0-are-now-ga#:~:text=Spring%20Security%206%20requires%20JDK%2017%20and%20uses%20the%20jakarta%20namespace.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=upate
spring.datasource.url=jdbc:mysql://localhost:3306/database_name
spring.datasource.username=admin
spring.datasource.password=admin1234

Spring boot - Deploy war Application in Tomcat Root

I'm implementing a Spring boot application and i have have this requirements:
1 - The generated application must be a war
2 - Deployed as a war in the tomcat root
3 - we don't have to configure anything in tomcat
we are using spring boot 2 and tomcat 9
in our development envrionment we can start the application by the main and as default the spring boot strat it in the root context root \ as requested, this is the standard behaviour of spring boot
instead when we deploy the application in tomcat we are not able to let it start as root.
We know already the work around like renaming the final war ROOT.war, that the application will overwrite the dafault root application in tomcat that has use the \ context root, but this is not an elegant solution, we would like to understand what is the problem
By default if you doplay a spring boot application like a war in tomcat it use the war name as context root : i mean for exampl text.war then the context root will be \test
but if we try to modify the property server.servlet.context-path whatever we put in it
it could be the empty context root that we would like to achieve server.servlet.context-path=\
or another name that doenst mathch with the war name (liek server.servlet.context-path=\test2 ) the application is not properly published in tomcat (404 resource not available)
clearly if instead the war name and the configured server.servlet.context-path match all working properly
we know also the we can configure the server.xml and force the application
to use the context root that we want:
The point that we are not able to understand is
1 - why when we deploy the war in tomcat we cannot configured the server.servlet.context-path becouse if the path configured doesn't match with the war name the app is to reachable
2 - sameone foud a decent solution to automatically deploy the app as context root

Springboot Strange Resource Loading Behavior

I'm working on a springboot 1.5.1 application that I'm trying to load a WSDL included in my resources directory in the wsdl directory. Depending on where my application executes I'm getting different results (command line, intellij, cloud foundry) and I can't seem to get all three to work at the same time.
I've tried several ways of locating the resource:
From prior to the migration to springboot we had this (worked in IntelliJ but not java -jar myboot.jar):
this.getClass().getResource("/wsdl/my.wsdl");
I switched it to the typically more correct version and got it to work in IntelliJ and java -jar but not Cloud Foundry:
this.getClass().getClassLoader().getResource("/wsdl/my.wsdl");
I switched it to use the Spring Resource Loader version and it worked in IntelliJ and CloudFoundry but not java -jar:
#Value("classpath:/wsdl/my.wsdl")
private Resource wsdlResource;
wsdlResource.getURL();
On the command line what I've noticed is that it seems to be thinking that BOOT-INF/classes is a JAR file (Note the ! after classes):
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL at: jar:file:/C:/dev/redacted/build/libs/redacted.jar!/BOOT-INF/classes!/wsdl/my.wsdl. It failed with:
JAR entry BOOT-INF/classes!/wsdl/my.wsdl not found in C:\dev\redacted\build\libs\redacted.jar.
From looking at IntelliJ's URL, it's referring to the actual source folder which explains why it seems to always work.
What is causing this and how might I universally load these class path resources successfully with springboot?

Deployment of war file on redhat openshift

I created a spring mvc application (java based configuration no web.xml, no any xml anywhere) in eclipse as a dymamic web application project.I uploaded the war file to my tomcat 7 cartridge using git as documented here https://help.openshift.com/hc/en-us/articles/202399740-How-to-deploy-pre-compiled-java-applications-WAR-and-EAR-files-onto-your-OpenShift-gear-using-the-java-cartridges
git finishes with a "deployment completed with status: success" message but when i try to access the deployed app under http://ashken-f00fc7c8.rhcloud.com/webservice/ it returns a http status code 404 yet on my local machine everything runs fine.
The problem was a result of java versioning hell. I had compiled my project with java 8 which is not yet supported by the tomcat 7 catridge. so downgrading to java 7 solved the issue. java 8 is supported by the openshift DIY catridges though.

Resources