spring 切换开发和生产环境
2018-03-02 17:05
204 查看
在开发中,我们一般把环境分为开发环境和正式的产品环境,为了方便我们在两个环境之间的切换,spring给我们提供了很好的支持。
首先,在项目中,我们建立三个yml
其中,application.yml 我们用来负责对开发环境和产品环境的切换,application-dev.yml对开发环境的进行相关配置,application-product是对产品环境进行相关的配置。这个配置很简单:
application.yml中
spring:
profiles:
active: productapplication-dev.yml中
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: xxx
url: jdbc:mysql://127.0.0.1/sell?characterEncoding=utf-8&useSSL=false
server:
context-path: /demo
port: 8086
logging:
level:
com.example.demo.mapper: trace
..........
application-production.yml中
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: xxx
url: jdbc:mysql://127.0.0.1/sell?characterEncoding=utf-8&useSSL=false
server:
context-path: /demo
port: 8087
..........然后我们在application.yml中,对spring.profiles.active = dev 或者 spring.profiles.active = product 切换,然后启动项目,就可以从启动的端口看看你的配置是否成功,快去试试吧
首先,在项目中,我们建立三个yml
其中,application.yml 我们用来负责对开发环境和产品环境的切换,application-dev.yml对开发环境的进行相关配置,application-product是对产品环境进行相关的配置。这个配置很简单:
application.yml中
spring:
profiles:
active: productapplication-dev.yml中
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: xxx
url: jdbc:mysql://127.0.0.1/sell?characterEncoding=utf-8&useSSL=false
server:
context-path: /demo
port: 8086
logging:
level:
com.example.demo.mapper: trace
..........
application-production.yml中
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: xxx
url: jdbc:mysql://127.0.0.1/sell?characterEncoding=utf-8&useSSL=false
server:
context-path: /demo
port: 8087
..........然后我们在application.yml中,对spring.profiles.active = dev 或者 spring.profiles.active = product 切换,然后启动项目,就可以从启动的端口看看你的配置是否成功,快去试试吧
相关文章推荐
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Spring.profile实现开发、测试和生产环境的配置和切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Maven项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Maven+Spring Profile实现生产环境和开发环境的切换
- Spring.profile实现开发、测试和生产环境的配置和切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- spring容器内建的profile功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Gradle项目之Spring.profile.开发.测试.生产环境的配置和切换之一键部署
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
- Spring.profile实现开发、测试和生产环境的配置和切换