简体   繁体   English

SpringBoot:配置生产与开发环境

[英]SpringBoot: Configuration Production Vs Development environments

I have a problem with SpringBoot 1.5.1. 我对SpringBoot 1.5.1有问题。 I've create application.properties and application-dev.properties for my dev enviroment. 我已经为我的开发环境创建了application.propertiesapplication-dev.properties

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). 主要区别在于持久性:在生产( application.properties )中有一个JNDI(在Tomcat上配置),在dev中有一个本地数据库(H2)。

This is my conf in application.properties : 这是我在application.properties配置application.properties

spring.datasource.jndi-name=jdbc/db

And this is the application-dev.properties : 这是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!!!! 我的应用程序停止,因为它找不到JNDI jdbc / db !!!! I'm trying to change log configuration on my application-dev.properties and it works! 我试图更改我的application-dev.properties上的日志配置,并且它可以正常工作! But not the changes on persistence configuration. 但不更改持久性配置。

Thanks in advance 提前致谢

All the properties of application-dev.properties overrides the properties in application.properties . 的所有属性application-dev.properties覆盖在属性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. 但是,如果application.properties中的属性不是在开发人员中设置的,则它们也将包含在上下文中。 And if the property spring.datasource.jndi-name is enabled all the spring.datasource properties are ignored. 如果启用了spring.datasource.jndi-name属性,则所有spring.datasource属性都将被忽略。

The solution is to create another properties file like application-prod.properties and set the spring.datasource.jndi-name there. 解决方案是创建另一个属性文件,例如application-prod.properties并在其中设置spring.datasource.jndi-name The datasource stuff can stay in application-dev.properties . 数据源的内容可以保留在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 application.properties文件中,应启用要使用的配置文件: spring.profiles.active=prodspring.profiles.active=dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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