1、properties文件內容映射到類對象(屬性),如Resource目錄下的1.properties文件已配置前綴為com.imooc.people相關的信息,然后: pom添加依賴:springboot-configuration-processor People類對象上方添加注解: @Configuration @PropertySource(value="classpath:1.properties") //指定從哪個properties讀取內容 @ConfigurationProperties(prefix="com.imooc.people") //指定讀取的前綴 public class{ private String name; private String age; 。。。name、age的getter/setter。。。 } 然后直接在controller中@Autowired可直接獲取到有屬性值的People對象 2、yml文件內容映射到類對象(屬性),yml 格式不支持 @PropertySource 注解導入,一般用@Value。如Resource目錄下的1.properties文件已配置前綴為com.imooc.people相關的信息,然后: @Configuration //或者@Component public class{ @Value("${com.imooc.people.name}") private String name; @Value("${com.imooc.people.age:#{null}}") //age取不到對應配置值時,采用默認值null賦值 private String age; 。。。name、age的getter/setter。。。 }