spring-boot:如果密码失败,则在没有数据库的情况下启动应用程序

标签 spring hibernate spring-boot spring-data-jpa datasource

我在两个具有不同数据库密码的实例中使用该应用程序。我的代码只需要访问和查询一个实例,而不需要访问另一个实例上的数据库。如果我尝试使用错误的密码部署应用程序,它会给我“密码身份验证”错误并且不会启动应用程序。

我希望应用程序在密码验证失败时忽略数据库连接。

这是我的 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/

相关文章:

java - 当我将元素从一个包移动到另一个包时出现 ObjectDeletedException

java - 即使类路径中存在依赖项,Spring Boot也会显示 'can not be resolved'

java - 如何使用 Java Spring 从缓存中删除特定键

java - 当我的应用程序停止时我该如何捕获?

hibernate - 修复 hibernate 错误 "Use of the same entity name twice"

java - 无法写入内容: failed to lazily initialize a collection of role using OpenEntityManagerInViewFilter

spring-boot - 如何为开发目的禁用 Spring Cloud Stream 绑定(bind)?

spring - 如何在spring mvc项目中使用jSTL获取requestURI?

java - Spring Boot init.d not 未运行(未找到进程)

java - postgres 表不显示默认值