我在两个具有不同数据库密码的实例中使用该应用程序。我的代码只需要访问和查询一个实例,而不需要访问另一个实例上的数据库。如果我尝试使用错误的密码部署应用程序,它会给我“密码身份验证”错误并且不会启动应用程序。
我希望应用程序在密码验证失败时忽略数据库连接。
这是我的 application.properties 文件。
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版本为1.5.9
最佳答案
您可以在没有数据源的情况下运行 spring boot 应用程序。为此,您必须禁用数据源的自动配置,也可能禁用 JPA 自动配置。将以下行放入您的 @SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
关于spring-boot:如果密码失败,则在没有数据库的情况下启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49972442/