SpringBoot 快速简单读取properties文件
2017-10-09 11:03
316 查看
1、添加maven依赖注解
2、添加读取properties文件PropertiesConfig类
<!-- 做动态properties的getter/setter赋值方法: --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency>
2、添加读取properties文件PropertiesConfig类
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.io.ClassPathResource; /** * 读取properties文件 * Created by CatalpaFlat on 2017/8/11. */ @Configuration public class PropertiesConfig { @Bean public PropertySourcesPlaceholderConfigurer createPropertySourcesPlaceholderConfigurer() { ClassPathResource resource = new ClassPathResource("properties/base.properties"); PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer(); propertyPlaceholderConfigurer.setLocation(resource); return propertyPlaceholderConfigurer; } }
相关文章推荐
- 微服务,微架构[五]之springboot读取properties文件
- SpringBoot:四种读取properties文件的方式
- Spring Boot Properties文件读取
- Spring Boot的properties配置文件读取
- springboot如何读取配置文件中的参数(例如:application-consts.properties) 又结合maven读取配置文件的顺序
- Spring-boot中读取核心配置文件application和自定义properties配置文件的方式
- SpringBoot四种读取properties文件的方式
- spring boot学习2之properties配置文件读取
- SpringBoot内部配置:“application.properties配置”和”使用XML配置”,读取属性文件中的内容,日志配置,Profile配置(学习:SpringBoot实战)
- Spring Boot四种读取properties文件的方式
- springboot的application.properties配置文件的配置项读取
- springboot之读取properties属性文件
- SpringBoot四种读取properties文件的方式
- springboot读取properties文件的方式
- SpringBoot 读取properties文件并写入实体类
- Spring Boot 读取properties配置文件
- Spring Boot的properties配置文件读取
- spring中属性文件properties的读取
- IDEA-------(二)快速创建一个简单的Spring boot项目
- Spring 如何读取properties文件内容