简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM