springboot获取application.yml中的配置信息

HelloController.java
package com.springbootweb.demo.controller; import com.springbootweb.demo.entity.MyConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class HelloController { @Value("${myconfig}")
private String myconfig; @Value("${age}")
private String age; @Value("${content}")
private String content; //@RequestMapping("/hello")
@RequestMapping(value={"/hello","hi"})
public String say(){
String str="hello spring boot》》》》"+myconfig+";age:"+age;
str+="====";
str+=content;
return str;
} @Autowired
private MyConfigProperties cof; @RequestMapping("/conf")
public MyConfigProperties getConfig(){
return cof;
}
}
MyProperties.java
package com.springbootweb.demo.entity; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; @Component
@ConfigurationProperties(prefix = "myconfig1")
public class MyConfigProperties {
private String name;
private Integer age; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
}
}
DemoApplication
package com.springbootweb.demo; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Application.yml
server:
port: 8081
context-path: /t
myconfig: gys
age: 25
content: "myname:${myconfig},age:${age}"
myconfig1:
name: gysssssdddd
age: 35
springboot获取application.yml中的配置信息的更多相关文章
- SpringBoot 从application.yml中通过@Value读取不到属性值
package cn.exrick.xboot.mqtt; import org.eclipse.paho.client.mqttv3.*;import org.eclipse.paho.client ...
- springboot在application.yml中使用了context-path属性导致静态资源法加载,如不能引入vue.js,jquery.js,css等等
在springBoot配置中加入上下文路径 server.context-path=/csdn js,img等静态文件无法加载,出现404的问题 <script type="text/ ...
- springboot读取application.properties中自定义配置
假设在application-xxx.properties中配置 user.name=yuhk 一.在Controller中读取 @Value("{$user.name}") pr ...
- SpringBoot static修饰的字段/方法如何获取application.yml配置
SpringBoot的application.yml一种特殊的应用场景,一般我们获取application.yml的配置文件只要@Value就可以获取到值了,但是如果是static修饰的字段肯定就不能 ...
- SpringBoot读取yml中的配置,并分离配置文件
前言 在项目中经常遇到需要读取配置文件中的配置信息,这些配置信息之所以不写在代码中是因为实际项目发布或者部署之后会进行更改,而如果写在代码中编译之后没有办法进行修改. 之前使用的是properties ...
- SpringBoot学习(七)-->SpringBoot在web开发中的配置
SpringBoot在web开发中的配置 Web开发的自动配置类:在Maven Dependencies-->spring-boot-1.5.2.RELEASE.jar-->org.spr ...
- application.yml 常用基本配置
前言 在平时的项目开发中,自己对application.yml的配置的写法较为熟悉,现在自己就application.yml常用的配置进行总结如下: 1.Tomcat 配置 server: #设置请求 ...
- SpringBoot配置文件 application.properties,yaml配置
SpringBoot配置文件 application.properties,yaml配置 1.Spring Boot 的配置文件 application.properties 1.1 位置问题 1.2 ...
- Spring Boot项目application.yml文件数据库配置密码加密
在Spring boot开发中,需要在application.yml文件里配置数据库的连接信息,或者在启动时传入数据库密码,如果不加密,传明文,数据库就直接暴露了,相当于"裸奔"了 ...
随机推荐
- MySQL Lock--MySQL加锁规则
===================================================================== 淘宝林晓斌总结 在可重复读事务隔离级别下,加锁规则如下: 原 ...
- 使用InternalsVisibleToAttribute给assembly添加“友元assembly”特性遭遇"强签名"
一.如何让Intenal成员暴露给另一个程序集 我们知道Modifier为Internal的类型成员仅限于当前程序集能够访问,但是在某些情况下,我们希望将它们暴露给另一个程序集.比较典型的应用场景包括 ...
- Linq中left join之多表查询
using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...
- python之路---03 整型 bool 字符串 for循环
十三.整型(int) 基本操作: 1.+ - * / % // ** 2. .bit_length() 计算整数在内存中占⽤的⼆进制码的⻓度 如: 十四.布尔值(bool) True False ...
- DocFetcher 本机文件搜索工具
优点: 支持的文件类型多 全文搜索 可以随时update索引
- axios 的使用方法
axios是一个基于promise的HTTP库, 可以再浏览器和node.js中使用 浏览器的兼容 安装 使用npm安装 npm install axios --save 使用bower安装 bowe ...
- [shell]find命令
find ./ -mtime 18 -exec ls -l {} \; 该范例中特殊的地方有 {} 以及 \; 还有 -exec 这个关键字,这些东西的意义为: {} 代表的是『由 find 找到的内 ...
- Maven3.5.0安装与配置+Eclipse应用
Maven是一个优秀的构建工具(类似于 Ant, 但比 Ant 更加方便使用),能帮助我们自动化构建过程,从清理.编译.测试到生成报告,再到打包和部署.只需要输入简单的命令,Maven就可以帮我们处理 ...
- idea补丁破解
1.下载JetbrainsCrack-2.9-release-enc.jar破解补丁,下载地址:http://idea.lanyus.com 2.将其放在你的安装 idea下面的根目录下面 3.修改根 ...
- MySQL Binlog解析
https://yq.aliyun.com/articles/238364?spm=5176.8067842.tagmain.52.73PjU3 摘要: 概述 MySQL的安装可以参考:Linux(C ...