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中的配置信息的更多相关文章

  1. SpringBoot 从application.yml中通过@Value读取不到属性值

    package cn.exrick.xboot.mqtt; import org.eclipse.paho.client.mqttv3.*;import org.eclipse.paho.client ...

  2. springboot在application.yml中使用了context-path属性导致静态资源法加载,如不能引入vue.js,jquery.js,css等等

    在springBoot配置中加入上下文路径 server.context-path=/csdn js,img等静态文件无法加载,出现404的问题 <script type="text/ ...

  3. springboot读取application.properties中自定义配置

    假设在application-xxx.properties中配置 user.name=yuhk 一.在Controller中读取 @Value("{$user.name}") pr ...

  4. SpringBoot static修饰的字段/方法如何获取application.yml配置

    SpringBoot的application.yml一种特殊的应用场景,一般我们获取application.yml的配置文件只要@Value就可以获取到值了,但是如果是static修饰的字段肯定就不能 ...

  5. SpringBoot读取yml中的配置,并分离配置文件

    前言 在项目中经常遇到需要读取配置文件中的配置信息,这些配置信息之所以不写在代码中是因为实际项目发布或者部署之后会进行更改,而如果写在代码中编译之后没有办法进行修改. 之前使用的是properties ...

  6. SpringBoot学习(七)-->SpringBoot在web开发中的配置

    SpringBoot在web开发中的配置 Web开发的自动配置类:在Maven Dependencies-->spring-boot-1.5.2.RELEASE.jar-->org.spr ...

  7. application.yml 常用基本配置

    前言 在平时的项目开发中,自己对application.yml的配置的写法较为熟悉,现在自己就application.yml常用的配置进行总结如下: 1.Tomcat 配置 server: #设置请求 ...

  8. SpringBoot配置文件 application.properties,yaml配置

    SpringBoot配置文件 application.properties,yaml配置 1.Spring Boot 的配置文件 application.properties 1.1 位置问题 1.2 ...

  9. Spring Boot项目application.yml文件数据库配置密码加密

    在Spring boot开发中,需要在application.yml文件里配置数据库的连接信息,或者在启动时传入数据库密码,如果不加密,传明文,数据库就直接暴露了,相当于"裸奔"了 ...

随机推荐

  1. java_oop_类与对象

    类与对象包方法 ========================================= 对象的概念类与对象的关系    万物皆对象        属性(名词)            对象的 ...

  2. java_架构与模式

    框架有哪些?C++语言的QT.MFC.gtk,Java语言的SSH,php语言的 smarty(MVC模式),python语言的django(MTV模式)等等设计模式有哪些?工厂模式.适配器模式.策略 ...

  3. React 中的 Component、PureComponent、无状态组件 之间的比较

    React 中的 Component.PureComponent.无状态组件之间的比较 table th:first-of-type { width: 150px; } 组件类型 说明 React.c ...

  4. getModifiers 方法解释。

    modifier: 字面意思修饰符. getModifiers  得到的就是 前面的 的修饰符 ,这个方法 字段和方法 都有.这个方法的值是 修饰符 相加的到的值. 例子: public class ...

  5. tornado请求头/状态码/接口 笔记

    set_header()/set_default_headers() set_header():设置请求头数据 set_default_headers():设置默认请求头数据 import torna ...

  6. 编译小米mini openwrt

    编译小米mini openwrt 1.下载openwrt源码包:进入要下载保存的文件目录,输入 git clone git://git.openwrt.org/15.05/openwrt.git 2. ...

  7. 【java】进制转换

    进制的表现形式: 十进制:0-9 ,满10 进1 八进制:0-7,满8进1,用0开头表示 十六进制:0-9,A-F,满16进1,用0x开头表示 十进制转换二进制: 原理:对十进制数进行除2运算,如37 ...

  8. 阅读<Video Test Pattern Generator v7.0>笔记

    阅读<Video Test Pattern Generator v7.0>笔记 1.数据宽度的问题 TotalDataWidth的计算公式: 疑问:为什么TotalDataWidth后面需 ...

  9. Xilinx FPGA开发环境vivado使用流程

    Xilinx FPGA开发环境vivado使用流程 1.启动vivado 2016.1 2.选择Create New Project 3.指定工程名字和工程存放目录 4.选择RTL Project 5 ...

  10. Thinkphp 3.1. 3 ueditor 1.4.3 添加水印

    1.引入Ueditor  <!-- 实例化编辑器 --> <script type="text/javascript"> window.UEDITOR_HO ...