user1716970 user1716970 - 3 months ago 38
Java Question

non embedded postgresql in spring boot

I'm trying to use a non embedded PostgreSQL database in Spring Boot. But when I try to run my application "mvn spring-boot:run", the application fails to start with the following message:

Cannot determine embedded database driver class for database type NONE

These are my dependencies from pom.xml:

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>

<dependency>
<!-- Eureka service registration -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>

<dependency>
<!-- Spring Cloud starter -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1206-jdbc42</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pew.common</groupId>
<artifactId>backend-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>

</dependencies>


this is my settings in application.yml:

spring:
profiles: dev
application:
name: resource-service
jpa:
database: POSTGRESQL
datasource:
platform: postgres
url: jdbc:postgresql://${postgresqlHost:localhost}:${postgresqlPort:5432}
username: ${postgresqlUsername:root}
password: ${postgresqlPassword:SomePassword}
driverClassName: org.postgresql.Driver


I can't find much information about this which makes me think that this is probably something really easy to get working...

Answer Source

When you execute "mvn spring-boot:run" you don't specify to use the Spring Bootdev profile while you want to configure the datasource properties for the dev profile :

profiles: dev

Besides, in application.yml you should reference the property : spring.datasource and not jpa.database.datasource that is not used by Spring.

You should write :

spring.datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://${postgresqlHost:localhost}:${postgresqlPort:5432}
    ...

Here is the documentation reference about the way to do it.