作用:资源文件中的配置属性映射到实体类属性
1.引入包
org.springframework.boot spring-boot-configuration-processor
2. 创建一个properties文件resource.properties
opensource.name=helloopensource.website=imooc.comopensource.language=java
3. 创建Resource.java
//@Configuration 声明使用配置文件@Configuration@ConfigurationProperties(prefix="opensource")@PropertySource(value="classpath:resource.properties")public class Resource { private String name; private String website; private String language;//getter.setter}
4. 需要使用的地方使用 自动装配
@Autowired
private Resource resource;