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

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

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 ?

changelog directory not found after spring boot 3 upgrade

After upgrade to spring boot 3, liquibasebase throws error
liquibase.exception.UnexpectedLiquibaseException: java.io.FileNotFoundException: JAR entry db/scripts/dml/importstatus.sql not found
the correct path is db/changelog/scripts/dml/importstatus.sql, somehow "changelog" gets removed.
Other changeSets work fine, error only happens in sqlFile with property
<property name="script-dir" value="scripts/dml" dbms="postgresql"/>
<changeSet id="insert-import-status">
<sqlFile path="${script-dir}/importstatus.sql"
splitStatements="false"
stripComments="false"
encoding="utf8"
relativeToChangelogFile="true"
endDelimiter=";"/>
</changeSet>
I tried to use path without property, use "scripts/dml/importstatus.sql" but still got same error.
This is a bug in Liquibase 4.17: https://github.com/liquibase/liquibase/issues/3393
Unfortunately, the Spring Boot dependency management suggests 4.17.2 in the latest releases, as 4.17 was the latest minor release at the time when Spring Boot 3 went GA.
You can either downgrade to 4.16.2 or upgrade to 4.18.0. For example, by overriding the property liquibase.version in your build.

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

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.

Spring Boot Configuration File Location From Tomcat

I'm trying to setup backend application so it gets different configuration files depending on env.
On dev env I would like to load default application.yml from classpath. This should be the case when I'm running the app via: mvn spring-boot:run or java -jar ./target/myapp.war
But when this app is running on Tomcat it should load application.yml from server specific file e.g. /etc/apps/myapp/application.yml (not default one from classpath) because server has different mongodb credentials etc...
I don't want to use profiles because this mean I need to put server credentials in project on github in application.yml. I just want that this is known by server administrator and developer don't know anything about it.
Is there any way how can I tell this application inside tomcat to load different configuration file.
In this Tomcat I have other applications that are using spring boot so I need some solution that is independent. Setting globally spring.config.location is not the case because all apps will load this one file.
You can use #PropertyResource annotation with context xml.
NOTE: ignoreResourceNotFound will help not throw exception when file not found, say for Dev env.
#Configuration
#PropertySources({
#PropertySource("classpath:application.properties"),
#PropertySource(value = "file:${config.file}", ignoreResourceNotFound=true)
})
public class AppConfig {
//...
}
/META-INF/context.xml
<Context>
<Parameter name="config.file" value="/yourpath/application.properties"/>
</Context>
If you don't want to save path in context.xml inside your project, there are other ways to define application level context depending on your tomcat version. Please refer here for details for tomcat 9.
If you want to read properties from external location then write bootstrap.yml in your application and delete application.yml.
bootstrap.yml:
spring:
config:
location: file:/home/external/properties/location/
name: application
profiles:
active: dev
file location: /home/external/properties/location/
suppose you need dev and prod environment.Then keep this 3 properties file in this location.
application.yml
application-dev.yml
application-prod.yml
Spring boot read application.yml properties first. If set active profile dev in bootstrap.yml then application.yml value overwirte by application-dev.yml.
Or you can use config server
Look at this

How to change crashHub port in Springboot

I am using Springboot in my project, i start an embedded Springboot application inside my App. My app is already having a crashHub which is conflicting with springBoot's crashHub, so how i can change the springBoot's crashHub port, I don't want to do it through a XML File.
There's an extensive list of configuration properties in Spring Boot's documentation, including those for configuring the ports used by the remote shell: shell.ssh.port and shell.telnet.port.
You should configure one or both of these properties in your application.properties file in src/main/resources.
Additionally, you can do it by specifying parameter to java:
-Dshell.ssh.port=<your-port>
Or command line argument for you application:
--shell.ssh.port=<your-port>

Resources