Anatoli
Anatoli

Reputation: 11

Spring Boot JPA application does not start with spring boot 2.0.2 and it works fine with Spring boot 1.5.13

If I create empty Spring Boot JPA application which connects to PostgresSQL it works fine with Spring Boot 1.5.13. It does not work with Spring Boot 2.0.2.

Steps to recreate: 1. Create new Spring Boot application using SPRING INITIALIZR (https://start.spring.io/). Select the following dependencies "DevTools", "Web", "JPA", "JDBC" "PostgreSQL" during project initialization

  1. Add database connection properties to application.properties:

    spring.datasource.url=jdbc:postgresql://localhost:5432/my_db_name
    spring.jpa.hibernate.ddl-auto=none
    spring.datasource.driverClassName=org.postgresql.Driver
    spring.datasource.platform=postgres
    spring.datasource.username=my_user_id
    spring.datasource.password=my_password
    spring.jpa.database=POSTGRESQL
    spring.jpa.show-sql=true
    
  2. Start Spring Boot application

Steps above works fine if I select Spring Boot 1.5.13 using project creation. I keep getting error message below in Spring Boot 2.0.2:

 Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be 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).

Upvotes: 1

Views: 2600

Answers (2)

Anatoli
Anatoli

Reputation: 11

I tried to convert my application from Spring Boot Spring boot 1.5.13 to 2.0.2 and I finally figured out what was the issue. Several months ago I worked on another project and I added SPRING_CONFIG_LOCATION = C:\...path...\application.yml to my Windows environment variables. (I tested how external configuration works with Grails 3.3). I forgot to remove this environment variable.

It did not impact my Spring boot 1.5.13 application. It did impact my 2.0.2 Spring boot application, apparently it did not use application.yml in src/main/resources if SPRING_CONFIG_LOCATION is set. Thus, it is not a Spring boot issue per se, it was my computer configuration issue. Different behavior for 1.5.3 and 2.0.4 made it confusing.

If you have a similar issue, I would suggest to make sure that your application.properties or application.yml file is indeed read by Spring Boot during start up. You can do this by turning on debug logging during startup. You can turn it on by adding this statement to application.yml (or similar to application.properties):

logging:
  level:
    ROOT: DEBUG
debug: true

If debug statements do not appear during startup after this, it means that your application.yml or application.properties is not read. In this case turn on debugging by --debug flag. I use gradle, so in my case start command is

gradlew bootRun --debug

Then review startup messages and see if application.properties or application.yml is read or if you have another issue.

Upvotes: 0

Meziane
Meziane

Reputation: 1667

Just use Spring Boot 1.5.13, the new version seems to have a bug: I got the same problem and after a long search I dicided to downgrad to the 1.5.13 version.

Upvotes: 0

Related Questions