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. hiveserver 占用内存过大的问题

    今天为了求解hiveserver占用内存过大的问题,特地加了hive在apache的邮件列表,讨论半天.特别说的是 里面的人确实很热情啊 ,外国人做事确实很认真,讨论帖发的时候都狠详细. 粘出一些记录 ...

  2. MySQL 中的反引号(`):是为了区分 MySql 关键字与普通字符而引入的符号;一般,表名与字段名都使用反引号。

    MySQL 中的反引号(`):是为了区分 MySql 关键字与普通字符而引入的符号:一般,表名与字段名都使用反引号.

  3. python 术语

    python 术语 术语英文 术语中文 说明 PyPI(Python Package Index) 搜索python包的网站:https://pypi.org/ pip.easy_install 包管 ...

  4. npx:npm包执行器

    npx 作用: 单次执行命令而不需要安装到本机 执行依赖包里的二进制文件 使用不同版本的 node 利用 npx 可以下载模块这个特点,可以指定某个版本的 Node 运行脚本.它的窍门就是使用 npm ...

  5. EnvironmentError: mysql_config not found问题解决(centos7下python安装mysql-python)

    centos7下python安装mysql-python模块,执行命令: pip install mysql-python 出现报错:EnvironmentError: mysql_config no ...

  6. JS replace()用法实现replaceAll

    由于js没有提供replaceAll,则使用正则表达式实现全局替换. javascript中replace() 方法如果直接用str.replace("-","!&quo ...

  7. nginx的url规则小tips

    背景信息: 被代理的服务器(10.90.7.2)上,nginx的配置内容 server { listen ; server_name localhost; default_type text/html ...

  8. 基于zookeeper的activemq的主从集群配置

    项目,要用到消息队列,这里采用activemq,相对使用简单点.这里重点是环境部署. 0. 服务器环境 RedHat710.90.7.210.90.7.1010.90.2.102 1. 下载安装zoo ...

  9. Vivado HLS初识---阅读《vivado design suite tutorial-high-level synthesis》(4)

    Vivado HLS初识---阅读<vivado design suite tutorial-high-level synthesis>(4) 1.老样子,首先运行tcl脚本建工程: Vi ...

  10. 在同一台电脑安装python 2 和3,并且怎样安装各自的pip和模块

    安装python2.7 和 3.6不冲突直接安装就行 安装pip 访问https://pip.pypa.io/en/stable/installing/获取地址 curl https://bootst ...