Reputation: 151
I have a Spring Boot application with two profiles: 'dev' and 'prod'. In 'dev' profile should be used H2 database, in 'prod' — PostgreSQL.
They are defined in pom.xml as following:
<profiles>
<profile>
<id>prod</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
No other databases are in pom.xml defined.
In my application.properties file 'prod' profile is defined as active:
spring.profiles.active = prod
Also I have two specific properties files for each profile:
application-dev.properties:
spring.jpa.show-sql = true
and application-prod.properties (I deploy my app to AWS):
spring.datasource.url = jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username = ${RDS_USERNAME}
spring.datasource.password = ${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto = update
I start my IntelliJ IDEA with following VM-option:
-Dspring.profiles.active="dev"
When I start the program locally, I see that 'dev' profile is used (there is message in console "The following profiles are active: dev"), but H2 doesn't start. I become following error message:
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath.
If you have database settings to be loaded from a particular profile you may need
to active it (the profiles "dev" are currently active).
Please help me to define these profiles correctly.
Upvotes: 1
Views: 3170
Reputation: 131526
Cannot determine embedded database driver class for database type NONE
spring.datasource.url = jdbc:h2:mem:yourDB
spring.datasource.driverClassName = org.h2.Driver
added in application-dev.properties
file should solve your problem.
From Spring Boot documentation, it may be needed in some cases :
You often won’t need to specify the driver-class-name since Spring boot can deduce it for most databases from the url.
Edit
Maven profile is not Spring Boot profile.
when you run your project, enable also the maven profile with -P
arg:
mvn spring-boot:run -Pdev -Dspring.profiles.active="dev"
Edit
Update for handling production env problem.
Why overriding the version of postgresql provided by Spring in dependency?
Anyway, the version you use of postgresql driver has not the org.postgresql.jdbc.Driver
class but org.postgresql.Driver
.
So, specify that in the property file for prod config :
spring.datasource.driverClassName = org.postgresql.Driver
Upvotes: 1