在Spring中注入配置文件
来源:互联网 发布:有没有抢购软件 编辑:程序博客网 时间:2024/06/06 03:36
在项目工程中的可能会存在修改的属性,一般都是配置在外置的配置文件(.properties,.json,*.xml…)中。在使用时通过IO流读取并解析。 Spring框架对此进行了封装可以很方便的进行加载解析。
例如,存在文件 project.properties
# useruser.name=adminuser.pass=root
将配置文件注入spring存在两种方式:
1. 在spring的配置文件中注入
<!-- 注入配置文件 --> <context:property-placeholder location="classpath:project.properties" file-encoding="UTF-8" system-properties-mode="NEVER"/>
2. 在spring容器中声明一个类org.springframework.beans.factory.config.PropertyPlaceholderConfigurer中注入
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:project.properties</value> </list> </property> </bean>
使用属性:
@Value(value = "${user.name}") private String name; @Value(value = "${user.pass}") private String pass; // test value inject: [name=admin],[pass=root] System.out.println("test value inject: [name=" + name + "],[pass=" + pass + "]");
阅读全文
0 0
- 在Spring中注入配置文件
- struts中的Action层调用服务层时,不需要在Spring配置文件中做属性注入
- Spring配置文件中注入环境变量或其他配置文件变量
- spring整合struts2后,struts2的action中调用服务层时,不需要在spring配置文件中去注入
- spring-依赖注入 配置文件
- hibernateTemplate在Spring核心配置文件的注入问题
- spring的配置文件中bean的注入方式
- spring的配置文件中bean的注入方式
- Spring 中注入bean的properties配置文件位置问题解决
- spring中属性文件和配置文件的注入方式
- Spring 中注入bean的properties配置文件位置问题解决
- Spring中利用配置文件和@value注入属性值
- Spring中注入List Set Map Properties的配置文件
- spring 配置文件中如何注入map list set等类型
- Spring中利用配置文件和@value注入属性值
- spring中value可以使用配置文件注入值
- spring在构造函数中注入对象
- 在监听器中注入spring bean
- SwipeRefreshLayout + RecyclerView 实现上拉加载下拉刷新
- ios蓝牙开发(二)ios连接外设的代码实现
- 数据库事物
- Spring:IoC 用法(三、XML配置用法)
- 插入排序
- 在Spring中注入配置文件
- mybatis 处理结果集对象,对象包含对象[{a,b,c:[{}]}]
- 【HDU 1421】搬寝室
- Vue2 移动端开发环境搭建
- Unity3D项目程序加密2
- hibernate的表的映射和hql--第三天
- note____js
- 爬虫常用的三种通用模板小结
- BZOJ 1798 [Ahoi2009]Seq 维护序列seq 线段树