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
Spring Boot allows you to externalize your configuration so you can work with the same application code in different environments. You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration.
Spring MVC provides a decoupled way of developing web applications. With simple concepts like Dispatcher Servlet, ModelAndView, and View Resolver, it makes it easy to develop web applications.
Spring @Configuration annotation is part of the spring core framework. Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With