找不到 Spring 配置文件



我已将这个application-local.json创建为src/main/resources

{
"spring": {
"datasource": {
"url": "jdbc:postgresql://xxx:yyy/db",
"username": "xxx",
"password": "xxx",
"driverClassName": "org.postgresql.Driver"
},
"profiles": {
"active": "local"
}
}
}

另一方面,apliication.yml

spring:
jpa:
generate-ddl: false
show-sql: true
properties:
hibernate:
format_sql: true
jdbc:
lob:
non_contextual_creation: true
profiles:
active: local
management:
security:
enabled: false
endpoints:
web:
exposure:
include: '*'
---
spring:
profiles: local
server:
port: 8092

目前,我收到以下消息:

***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class

Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

当 Spring 应用程序运行时,它会从application.yml->spring->profiles->active的值加载属性。Spring 只支持yml.properties文件作为源代码。

因此,在您的情况下,Spring 将寻找应用程序本地。YML应用程序本地。用于读取配置文件特定属性的属性。

但在这里,您已将属性文件定义为应用程序本地文件。JSON,这也是春天不读取值并且您获得异常的原因。

解决方案创建本地应用程序。YML应用程序本地。属性并粘贴您的内容并尝试。它应该有效。

下面是示例数据库配置。

spring.datasource.url=jdbc:mysql://localhost:3306/_schema name_
spring.datasource.username=_username_
spring.datasource.password=_password_
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql = true
logging.level.org.hibernate.SQL=debug

相关内容

  • 没有找到相关文章

最新更新