首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到Spring配置文件

找不到Spring配置文件
EN

Stack Overflow用户
提问于 2018-06-18 12:18:43
回答 1查看 724关注 0票数 2

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

代码语言:javascript
复制
{
  "spring": {
    "datasource": {
      "url": "jdbc:postgresql://xxx:yyy/db",
      "username": "xxx",
      "password": "xxx",
      "driverClassName": "org.postgresql.Driver"
    },
    "profiles": {
      "active": "local"
    }
  }
}

另一方面,apliication.yml

代码语言:javascript
复制
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

目前,我收到这样的信息:

代码语言:javascript
复制
***************************
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).
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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配置。

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50909368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档