SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
2020-12-13 04:05
阅读:488
标签:过程 配置 rest 文件 return author boot 工具 选择
现在在的公司用
spring.profiles.active=@profiles.active@
当我看到这个的时候,一脸蒙蔽,这个@
是啥意思。
这里其实是配合 maven profile
进行选择不同配置文件进行开发
实战
1.构建一个springboot 项目
这里使用idea进行构建的,这个过程省略
2.pom文件配置
prod prod dev dev
true
test test
- 这里默认dev配置
3.配置多个配置文件
application.properties
注意这里的profiles.active 要和pom文件的对应上
spring.profiles.active=@profiles.active@
application-dev.properties
name = "dev"
application-prod.properties
name = "prod"
application-test.properties
name = "test"
4.编写个测试的controller
/**
* @author kevin
* @date 2019/6/28 16:12
*/
@RestController
public class HelloController {
@Value("${name}")
private String name;
@RequestMapping(value = {"/hello"},method = RequestMethod.GET)
public String say(){
return name;
}
}
5.启动测试
使用idea工具启动开发
默认是dev,假如想要使用prod配置文件,如上图选择prod,注意下面的导入,重启项目
D:\dev_code\profiles-demo\target>curl http://localhost:8080/hello
"prod"
6 打包
这里使用idea打包不再介绍,如果你使用命令
mvn clean package -P dev
则是使用dev配置
好了,玩的开心
SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
标签:过程 配置 rest 文件 return author boot 工具 选择
原文地址:https://www.cnblogs.com/zhenghengbin/p/11103998.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
文章链接:http://soscw.com/essay/28839.html
文章标题:SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
文章链接:http://soscw.com/essay/28839.html
评论
亲,登录后才可以留言!