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. MySQL Binlog常用参数

    ====================================================================== MySQL Binlog常用参数 log_bin 设置此参 ...

  2. centos配置apache的https服务

    因为公司要开发微信小程序,由于小程序比较特殊,需要https服务,所以就研究了下apache的https服务了,大致过程如下: 1.向证书机构申请https证书,会得到证书和私钥 2.安装apache ...

  3. 转载:扒一扒Profiler中这几个“占坑鬼”

    https://blog.uwa4d.com/archives/presentandsync.html WaitForTargetFPS.Gfx.WaitForPresent 和 Graphics.P ...

  4. 使用OpenCV进行人脸识别

    不断维护的地址:http://plzcoding.com/face-recognition-with-opencv/ 怎样使用OpenCV进行人脸识别 本文大部分来自OpenCV官网上的Face Re ...

  5. Yuan先生的博客网址

    1 Web应用  https://www.cnblogs.com/yuanchenqi/articles/8869302.html 2 http协议 https://www.cnblogs.com/y ...

  6. Hanlp中使用纯JAVA实现CRF分词

    Hanlp中使用纯JAVA实现CRF分词 与基于隐马尔可夫模型的最短路径分词.N-最短路径分词相比,基于条件随机场(CRF)的分词对未登录词有更好的支持.本文(HanLP)使用纯Java实现CRF模型 ...

  7. mvc 部署到iis 提示错误未能加载文件或程序集System.Web.Http.WebHost

    Nuget程序包管理 —>程序包管理控制台,运行以下命令即可: Update-Package Microsoft.AspNet.WebApi -reinstall

  8. Java NIO通信的基础,基于TCP C/S例子介绍

    为了更好的理解Netty异步事件驱动网络通信框架,有必要先了解一点Java NIO原生的通信理论,下面将结合基于TCP的例子程序,含客户端和服务端的源码,实现了Echo流程. Java NIO的核心概 ...

  9. IK分词器的使用

    1.下载 根据自己的版本进行下载 https://github.com/medcl/elasticsearch-analysis-ik/releases wget https://github.com ...

  10. 实现java随机数Random的几招

    一,在java.util这个包里面提供了一个Random的类,我们可以新建一个Random的对象来产生随机数,可以产生随机整数.随机float.随机double,随机long,这个也是我们经常用的一个 ...