spring 通过编程来获取属性文件
2023-09-11 14:21:41 时间
配置可以读取属性:
<beans profile="dev"> <context:property-placeholder ignore-resource-not-found="true" location="classpath:/META-INF/config/dev/*.properties" /> </beans> <beans profile="idc"> <context:property-placeholder ignore-resource-not-found="true" location="classpath:/META-INF/config/idc/*.properties" /> </beans> <beans profile="production"> <context:property-placeholder ignore-resource-not-found="true" location="classpath:/META-INF/config/prod/*.properties" /> </beans> <beans profile="test"> <context:property-placeholder ignore-resource-not-found="true" location="classpath:/META-INF/config/test/*.properties" /> </beans>
也可以通过编程的形式获取文件属性:
Resource resource = new ClassPathResource("/my.properties"); Properties props = PropertiesLoaderUtils.loadProperties(resource);
参考文献:
【1】http://stackoverflow.com/questions/1771166/access-properties-file-programatically-with-spring
相关文章
- Spring获取properties文件中的属性
- Spring boot中普通工具类不能使用@Value注入yml文件中的自定义参数的问题
- spring学习笔记(2)文件资源访问接口Resource
- spring的有状态BEAN和无状态BEAN
- spring boot单元测试之十三:用mockmvc测试文件下载(spring boot 2.4.4)
- spring boot单元测试之四:单元测试中测试文件上传(spring boot 2.4.3)
- spring boot:实现图片文件上传并生成缩略图(spring boot 2.3.1)
- [Java Spring] JPA CrudRepository query language
- 多种Spring.jar详解
- spring boot单元测试之十五:用mockmvc测试返回异步结果的controller(spring boot 2.4.4)
- Java常见的spring笔试选择题
- Scala 2.13.1 整合 Spring Boot 2.2.1开发web应用完整pom文件
- 《Spring Boot Cookbook》阅读笔记
- 我们为什么要使用Spring Cloud?
- Spring MVC更多家族成员----文件上传---06
- Java Spring ClassPathXmlApplicationContext是如何判断容器内包含某个Bean的
- Atitit spring单元测试 注解 获取服务名 Spring文件单独放在一个文件夹,去掉dubbo配置,方便测试 里面包含的mybatis 找不到,只好设置成相对于class绝对路径可以了
- Spring多数据源分布式事务管理/springmvc+spring+atomikos[jta]+druid+mybatis
- 优雅处理 Spring Boot 日志文件:高效、可维护的日志管理方案详解
- 保护亿万数据安全,Spring有“声明式事务”绝招
- Spring Boot配置MinIO(实现文件上传、下载、删除)
- 001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点
- Spring 按业务模块输出日志到不同的文件
- spring cloud: 二、服务的消费(ribbon和feign两种方式)