Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-boot: start application without database if password fails

I am using the application in two instances that have different database passwords. My code only needs to access and query one instance, and doesn't need to access database on another instance. If I try to deploy the app with wrong password, it gives me "password authentication" error and doesn't start the application.

I want the app to ignore the database connection if password authentication is failed.

Here is my application.properties file.

spring.security.enabled=false
management.security.enabled=false
security.basic.enabled=false

## Postgresql for storing backup details
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url= jdbc:postgresql://localhost:5432/dbName
spring.datasource.username=username
spring.datasource.password=password
#spring.datasource.continue-on-error=true
#spring.datasource.initialize=false
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL94Dialect
spring.datasource.primary.continueOnError=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

Spring boot version is 1.5.9

like image 701
user2798227 Avatar asked Jan 24 '26 21:01

user2798227


1 Answers

You can run spring boot application without datasource. For that you must disable the auto configuration of datasource and probably the JPA auto configuration as well. Place the below line in your @SpringBootApplication

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
like image 134
Ram Avatar answered Jan 26 '26 14:01

Ram