SpringBoot(十):读取application.yml下配置参数信息,java -jar启动时项目修改参数
读取application.yml下配置参数信息
在application.yml文件内容

my:
remote-address: 192.168.1.1
yarn:
weburl: http://192.168.1.1:8088/ws/v1/cluster/
security:
username: foo
roles:
- USER
- ADMIN
创建FooProperties.java文件,并使用@ConfigurationProperties注解
@Component
@ConfigurationProperties(prefix = "my")
public class MyPorperties {
private final Yarn yarn = new Yarn();
private InetAddress remoteAddress; private final Security security = new Security(); public InetAddress getRemoteAddress() {
return remoteAddress;
} public void setRemoteAddress(InetAddress remoteAddress) {
this.remoteAddress = remoteAddress;
} public Security getSecurity() {
return security;
} public Yarn getYarn() {
return yarn;
} public static class Security { private String userName;
private List<String> roles = new ArrayList<>(Collections.singleton("USER")); public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public List<String> getRoles() {
return roles;
} public void setRoles(List<String> roles) {
this.roles = roles;
} @Override
public String toString() {
return "Security{" + "userName='" + userName + '\'' + ", roles=" + roles + '}';
}
} public static class Yarn {
private String webUrl; public String getWebUrl() {
return webUrl;
} public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
} @Override
public String toString() {
return "Yarn [webUrl=" + webUrl + "]";
}
}
}
调用
@RestController
public class TestController {
@Autowired
private MyPorperties my; @RequestMapping("/myProperties")
public Map<String, Object> getFooProperties() {
Map<String, Object> map = new HashMap<>();
map.put("remote-address", my.getRemoteAddress());
map.put("security", my.getSecurity().toString());
map.put("yarn", my.getYarn().toString());
return map;
}
}
测试
访问:http://localhost:8080/myProperties

参考《https://blog.csdn.net/u013887008/article/details/79368173》
java -jar启动时项目修改参数
项目已经发布,在启动时可以通过传递参数修改启动参数:
java -jar \
-Dspring.profiles.active=prod \
-Dserver.port=8080 \
my-web-1.0.0-SNAPSHOT.jar
或者可以吧整个application.yml文件放在jar外边,启动时指定文件路径:
java -jar demo.jar --Dspring.config.location=路径(application.yml)
SpringBoot(十):读取application.yml下配置参数信息,java -jar启动时项目修改参数的更多相关文章
- springboot:读取application.yml文件
现在开发主要使用微服务框架springboot,在springboot中经常遇到读取application.yml文件的情形. 一.概述 开发过程中经常遇到要读取application.yml文件中的 ...
- docker-compose如何动态配置springboot项目的application.yml的配置
假如我们再springboot的工程中有配置文件 方式1: application.properties里面存在环境变量: #配置数据库链接 spring.datasource.url = jdbc: ...
- omcat配置多域名站点启动时项目重复加载多次
在tomcat中配置多个Host的时候, 出现项目重复启动多次的情况. 刚开始以为是spring boot发布项目的时候自带了一个tomcat引起的, 后来发现不是 参考了这两篇文章, 解决问题 ht ...
- SpringBoot在logback.xml中读取application.properties中配置的日志路径
1.在springboot项目中使用logback记录日志,在logback.xml中配置日志存储位置时读取application.properties中配置的路径,在 logback.xml中配置引 ...
- 不错的linux下通用的java程序启动脚本
不错的linux下通用的java程序启动脚本(转载) 虽然写起动shell的频率非常不高...但是每次要写都要对付一大堆的jar文件路径,新加jar包也必须要修改起动shell. 在网上找到一个挺好的 ...
- SpringBoot中application.yml基本配置详情
把原有的application.properties删掉.然后 maven -X clean install,或者通过Maven Project双击clean和install(1)端口服务配置 #端口 ...
- SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active
趁今天有时间整理了一下 启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 jav ...
- SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active(转)
趁今天有时间整理了一下 启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 jav ...
- SpringBoot(二) SpringBoot核心配置文件application.yml/properties
我们都知道在Spring中有着application.xml文件对Spring进行相关配置,通过web.xml中的contextConfigLocation指定application.xml文件所在位 ...
随机推荐
- Flask---第二个例子--Get和POST发送
*get:浏览器告诉服务器,我只需要获取页面信息给我,这是最简单最常用的方法 *Post:览器告诉服务器:想在 URL 上 发布 新信息.并且,服务器必须确保 数据已存储且仅存储一次.这是 HTML ...
- Codeforces 781D Axel and Marston in Bitland 矩阵 bitset
原文链接https://www.cnblogs.com/zhouzhendong/p/CF781D.html 题目传送门 - CF781D 题意 有一个 n 个点的图,有 m 条有向边,边有两种类型: ...
- Centos7使用yum命令安装Mysql5.6.X
首先:具体的安装步骤在mysql官方文档上都有详细的描述. 文档虽然是英文,不过很容易理解,我就不一一翻译了. 官方文档地址:https://dev.mysql.com/doc/refman/5.6/ ...
- ESP8266进阶篇
ESP8266进阶篇 20170225(应需要,继续使用此模块!!!) 说一下如何通过内网和外网来控制我的ESP8266的数据模块 1.内网控制:(要求手机直接连接在ESP8266的WIFI上面,使用 ...
- linux下执行.sh文件的方法和语法
linux下执行.sh文件的方法 .sh文件就是文本文件,如果要执行,需要使用chmod a+x xxx.sh来给可执行权限. 是bash脚本么 可以用touch test.sh ...
- RESTful架构&简单使用Django rest framework
RESTful架构 1 什么是REST REST全称是Representational State Transfer,中文意思是表述性状态转移. 它首次出现在2000年Roy Fielding的博士论 ...
- 浅谈云计算SPI(SaaS、PaaS、IaaS)
The other day, I arrived at the SAP LABS CHINA for interview with my pleasure. That gave me a chance ...
- Java NIO- 最好文档
http://www.cnblogs.com/puyangsky/p/5840873.html 1 背景介绍 在上一篇文章中我们介绍了Java基本IO,也就是阻塞式IO(BIO),在JDK1.4版本后 ...
- 创建emlog
第一步:解压安装包并且安装 第二步:打开phpstudy,并启动(如果安装后打开显示没有VC11,则要去安装) 第三步:打开“其他管理项菜单”下面的“根目录”,将emlog下面的emlog之下的全部文 ...
- codeforces651----A. Joysticks
//贪心,注意特判即可 #include <iostream> using namespace std; int main() { ; cin >> a >> b; ...