我已经将这个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).发布于 2018-06-18 16:40:08
当Spring应用程序运行时,它从application.yml->spring->profiles>active的值加载属性。Spring只支持yml和.properties文件作为源。
因此,在您的示例中,Spring将查找application-local.__yml或application-local.__properties来读取特定于配置文件的属性。
但是在这里,您已经将属性文件定义为一个application-local.__json,这是spring没有读取值并得到异常的原因之一。
创建application-local.__yml或application-local.__properties并粘贴内容并尝试解决方案。应该管用的。
下面是示例DB配置。
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=debughttps://stackoverflow.com/questions/50909368
复制相似问题