Java 如果我没有';不想在application.properties中设置数据源?
我有一个spring启动应用程序。还有一位博士后司机。但我不想设定Java 如果我没有';不想在application.properties中设置数据源?,java,spring,postgresql,spring-boot,Java,Spring,Postgresql,Spring Boot,我有一个spring启动应用程序。还有一位博士后司机。但我不想设定 spring.datasource.url=jdbc:postgresql://localhost:5432/app spring.datasource.username=postgres spring.datasource.password=qwerty 在application.properties中,因为我后来在代码中这样做了 如果删除此部分,我会遇到以下问题: Description: Failed to conf
spring.datasource.url=jdbc:postgresql://localhost:5432/app
spring.datasource.username=postgres
spring.datasource.password=qwerty
在application.properties中,因为我后来在代码中这样做了
如果删除此部分,我会遇到以下问题:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine suitable jdbc url
如何修复它
UPD:
Spring Boot自动配置数据源:如果您不想这样做,因为您想自己处理它或出于其他原因(例如,我在单元测试期间禁用了它),那么可以使用注释
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class
})
您必须在
.properties
文件中定义它,然后将其用作java类的源代码,因为在单独的文件中定义属性是最佳实践。
例如,我在Hibernate配置类的注释中使用数据库属性
@PropertySource(value=“classpath:db.properties”)
“我后来在代码中完成了。”显示您的代码
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class
})