springboot属性配置
来源:互联网 发布:javascript 跳转页面 编辑:程序博客网 时间:2024/05/16 06:06
1.引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
2.配置文件(application.yml)
要注意属性名冒号后与值要有一个空格
girl: age: 100 size: hello3.创建一个属性类(GirlPropertiespackage com.example.Properties;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;/** * Created by wangjiwei on 2017/5/3. */@Component@ConfigurationProperties(prefix = "girl")public class GirlProperties { private Integer age; public String getSize() { return size; } public void setSize(String size) { this.size = size; } private String size; public GirlProperties() { super(); } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; }})
测试package com.example.controller;import com.example.Properties.GirlProperties;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * Created by wangjiwei on 2017/5/2. */@RestControllerpublic class HelloController { @Autowired private GirlProperties girlProperties; @RequestMapping(value = "/*") public String sayHello(){ return girlProperties.getSize(); }}
1 0
- SpringBoot配置属性系列
- springboot属性配置
- SpringBoot配置属性
- SpringBoot配置属性之MVC
- SpringBoot配置属性之Server
- SpringBoot配置属性之DataSource
- SpringBoot配置属性之NOSQL
- SpringBoot配置属性之MQ
- SpringBoot配置属性之Security
- SpringBoot配置属性之Migration
- SpringBoot配置属性之其他
- SpringBoot配置属性之MQ
- SpringBoot配置属性之DataSource
- SpringBoot配置属性之MVC
- SpringBoot配置属性之Server
- SpringBoot配置属性之DataSource
- SpringBoot配置属性之NOSQL
- SpringBoot配置属性之MQ
- ORA-01461: can bind a LONG value only for insert into a LONG column
- 人物列表
- 轻量级分布式 RPC 框架
- timer+timertask 制作定时器
- 2017百度实习生笔试编程题
- springboot属性配置
- Android 技术重温系列 ( 5 )
- struts1配置文件中action的常用属性
- 转载:最值得反思:迟到太久不必到
- 瑞神要考研(并查集)
- 新建项目直接修改UTF-8格式
- 【并查集】nyoj711
- 并查集
- mysql条件统计小例子