开发配置:
- IntelliJ Idea
- JDK 1.8.0.131 64-bit
- spring boot 1.5.8
1.新建自定义配置文件
student:
name: Jack
age: 16
score:
math: 90
english: 80
2.新建配置文件对应的类
package com.example.demo.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "student")
@PropertySource(value = "classpath:config/my-config.yml",factory=YamlPropertySourceFactory.class)//指定factory
public class Student {
private String name;