Luis C.
Luis C.

Reputation: 755

SpringBoot: Configuration Production Vs Development environments

I have a problem with SpringBoot 1.5.1. I've create application.properties and application-dev.properties for my dev enviroment.

The main difference is the persistence: in production (application.properties) there is a JNDI (configured on Tomcat) and in dev there is a local db (H2).

This is my conf in application.properties:

spring.datasource.jndi-name=jdbc/db

And this is the application-dev.properties:

spring.datasource.url=jdbc:h2:file:~/db
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver

But when I'm starting in with dev profile

2017-02-24 15:25:39.948  INFO 7912 --- [           main] it.geny.MmqApplication                   : The following profiles are active: dev

my app stops because it didn't find the JNDI jdbc/db!!!! I'm trying to change log configuration on my application-dev.properties and it works! But not the changes on persistence configuration.

Thanks in advance

Upvotes: 7

Views: 11275

Answers (1)

Patrick
Patrick

Reputation: 12744

All the properties of application-dev.properties overrides the properties in application.properties. But if in application.properties are properties which are not set in the dev one they will be also inlcuded to the context. And if the property spring.datasource.jndi-name is enabled all the spring.datasource properties are ignored.

The solution is to create another properties file like application-prod.properties and set the spring.datasource.jndi-name there. The datasource stuff can stay in application-dev.properties.

In your application.properties file you should enable the profile you like to use: spring.profiles.active=prod or spring.profiles.active=dev

Upvotes: 11

Related Questions