版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z_demon801/article/details/80663943
1. pom.xml 需要添加 spring-boot-configuration-processor
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
2. 创建资源配置文件
例如属性为:
com.merverille.name=the_sardine
com.merverille.age=20
com.merverille.sex=1
3. 创建实体类 读取资源配置
创建和访问自定义配置设
@Configuration
@ConfigurationProperties(prefix = "com.merverille")
@PropertySource(value="classpath:resouces.properties")