Search code examples
spring-bootspring-config

Spring Config profile file is not found


I've created this application-local.json into src/main/resources:

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

By other hand, 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

Currently, I'm getting this message:

***************************
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).

Solution

  • When Spring application runs, it load properties from value of application.yml->spring->profiles->active. Spring supports only yml and .properties file as a source.

    So, in your case Spring will look for application-local.yml or application-local.properties to read profile specific property.

    But here, you have defined property file as a application-local.json and that a reason why spring is not reading values and you are getting exception.

    Solution Create application-local.yml or application-local.properties and paste your content and try. It should work.

    Here is sample DB configuration.

    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