springboot自定义配置文件(yml)

conf.yml

name: jennie
age: 18
#	friends: 

bean(Student)

package com.fr.springboot1.properties;

import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@PropertySource("classpath:conf.yml")
@ConfigurationProperties()
public class Student {
	private String name;
	private String age;
	private Map<String,Object> friends;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public Map<String, Object> getFriends() {
		return friends;
	}

	public void setFriends(Map<String, Object> friends) {
		this.friends = friends;
	}


}

Controller(StudentController)

package com.fr.springboot1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fr.springboot1.properties.Student;

@RestController
public class StudentController {

	private Student student;

	
	@Autowired
	public StudentController(Student student) {
		this.student = student;
	}

	@RequestMapping("/student")	
	public Student student() {
		return student;
	}

}

测试结果:

springboot自定义配置文件(yml)