Spring Boot 使用IntelliJ IDEA创建一个web开发实例(四)
多环境配置
1. 在springBoot多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,例如:
(1)application-dev.properties 对应开发环境 (2)application-test.properties 对应测试环境 (3)application-pro.properties 对应生产环境

application.properties
#激活哪一个环境的配置文件 spring.profiles.active=dev
server.port = 8081
server.servlet.context-path=/demo name = hello demo
application-dev.properties
server.port = 8082
server.servlet.context-path=/demo2 name = hello demo dev
application-pro.properties
server.port = 8083
server.servlet.context-path=/demo3 name = hello demo pro
application-test.properties
server.port = 8084
server.servlet.context-path=/demo4 name = hello demo test
对于哪个配置会生效,需要在application.properties中通过spring.profiles.active属性来设置,其值对应{profile}值,例如:
spring.profiles.active=dev 就会加载开发环境配置的信息。
2. 编写Controller类测试
package com.example.demo; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class DemoController {
@Value("${name}")
String name; @RequestMapping("name")
public String name() {
return name;
} @RequestMapping("hello")
public String hello() {
return "hello world!";
}
}
3.运行
application.properties
spring.profiles.active=dev

对应的是application-dev.properties配置。
修改application.properties
spring.profiles.active=test

对应的是application-test.properties配置。
Spring Boot 使用IntelliJ IDEA创建一个web开发实例(四)的更多相关文章
- Spring Boot 使用IntelliJ IDEA创建一个web开发实例(一)
.新建项目File-->New-->Project-->Spring Initializr 点击Finish,一个Spring Boot web应用就创建好了.
- Spring Boot 使用IntelliJ IDEA创建一个web开发实例(二)
1. 创建一个Controller类 package com.example.demo; import org.springframework.web.bind.annotation.RequestM ...
- Spring Boot 使用IntelliJ IDEA创建一个web开发实例(五)
使用application.ym进行多环境配置 1.配置激活选项 spring: profiles: active: dev 2.在配置文件添加若干个英文状态下的短横线即可区分 spring: pro ...
- Spring Boot 使用IntelliJ IDEA创建一个web开发实例(三)
属性配置 1.配置application.properties文件 配置web访问端口和context path server.port = 8081 server.servlet.context-p ...
- Intellij Idea 创建一个Web项目
今天想用IDEA创建一个web项目: 准备工具 1.jdk1.7 2.tomcat6.0,由于下载的8.5没有lib目录不能配置改6.0 3.idea2019.1.2 Intellij Idea的安装 ...
- Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目
Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...
- Spring Boot 多模块项目创建与配置 (一) (转)
Spring Boot 多模块项目创建与配置 (一) 最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都 ...
- Spring Boot 多模块项目创建与配置 (一)
最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都使用spring boot框架.之前有零零散散学过一些 ...
- Spring Boot 多模块项目创建与配置 (转)
转载:https://www.cnblogs.com/MaxElephant/p/8205234.html 最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多 ...
随机推荐
- AOP:jdk的动态代理
1.文件结构 2.建立接口 package com.wangcf.manager; public interface IUserManager { public void add(); public ...
- 线段树-hdu2795 Billboard(贴海报)
hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接 ...
- 字典树---2001 POJ Shortest Prefixes(找最短前缀)
做的第一道字典树的题,算比较水的: -->>>:传送门 代码: #include <stdio.h> #include<stdlib.h> #define M ...
- Web.config配置configSections学习
文章:c# 配置文件之configSections配置 configSections节点需要位于configuration第一的位置,紧挨configuration. <configuratio ...
- Servlet中常用对象及API类之间的关系
Servlet最常用的对象: 请求对象:ServletRequest和HttpServletRequest,通过该对象获取来自客户端的请求信息 响应对象:ServletResponse和HttpSer ...
- 使用qemu-img创建虚拟磁盘文件
# 安装qemu-img yum install -y qemu-img # 获取帮助 qemu-img --help # 支持的虚拟磁盘文件格式 Supported formats: vvf ...
- linux 转移mysql文件操作流程
1.现将mysql停服 2.将文件拷贝到指定目录cp ./sales_trade_2.ibd /db/data/mysql/data_warehouse/sales_trade_2.ibd 3.检查新 ...
- 爬虫学习之-urlparse之urljoin()
首先导入模块,用help查看相关文档 >>> from urlparse import urljoin >>> help(urljoin) Help on func ...
- puthon进程开发
进程 本节目录 一 背景知识 二 什么是进程 三 进程调度 四 并发与并行 五 同步\异步\阻塞\非阻塞 六 进程的创建与结束 七 multiprocess模块 八 进程池和mutiprocess.P ...
- BZOJ4977 跳伞求生(贪心)
如果现在选定了一些要求消灭的敌人而不考虑积分,显然应该让每个敌人被刚好能消灭他的人消灭.再考虑最大化积分,显然我们应该优先消灭ci-bi大的敌人,所选用的a也应尽量大.于是按ci-bi从大到小排序,用 ...