2

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).
Jordi
  • 20,868
  • 39
  • 149
  • 333
  • Is your `application-local.yml` a YAML or JSON file?? – tan9 Jun 18 '18 at 12:21
  • it's using json format. Sorry, it's a miswriting. The filename is `application-local.json` – Jordi Jun 18 '18 at 12:25
  • 1
    Spring Boot only supports .properties and .yml/.yaml as sources of application properties. The only valid usage of JSON is providing configuration properties as a JSON string through `spring.application.json` application property. For more information: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html – tan9 Jun 18 '18 at 12:40
  • @tan9 can you please post your comment as answer. thank you – Simon Martinelli Jun 18 '18 at 13:43

1 Answers1

1

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
Shaunak Patel
  • 1,581
  • 11
  • 14