这里主要介绍PropertyPlaceholderConfigurer这个类的使用,spring中的该类主要用来读取配置文件并将配置文件中的变量设置到上下文环境中,并进行赋值。

一、此处使用list标签将多properties文件信息读取到PropertyPlaceholderConfigurer类中

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 这里支持多种寻址方式:classpath和file -->
<value>classpath:/opt/demo/config/demo-db.properties</value>
<!-- 推荐使用file的方式引入,这样可以将配置和代码分离 -->
<value>file:/opt/demo/config/demo-mq.properties</value>
<value>file:/opt/demo/config/demo-remote.properties</value>
</list>
</property>
</bean>

二、可以将多配置文件读取到list中,然后再将list的引用赋值

    <!-- 将多个配置文件位置放到列表中 -->
<bean id="propertyResources" class="java.util.ArrayList">
<constructor-arg>
<list>
<!-- 这里支持多种寻址方式:classpath和file -->
<value>classpath:/opt/demo/config/demo-db.properties</value>
<!-- 推荐使用file的方式引入,这样可以将配置和代码分离 -->
<value>file:/opt/demo/config/demo-mq.properties</value>
<value>file:/opt/demo/config/demo-remote.properties</value>
</list>
</constructor-arg>
</bean> <!-- 将配置文件读取到容器中,交给Spring管理 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" ref="propertyResources" />
</bean>

spring读取配置文件PropertyPlaceholderConfigurer类的使用的更多相关文章

  1. Spring 读取配置文件(二)

    Spring 读取配置文件并调用 bean package cn.com.test.receive; import org.springframework.beans.factory.annotati ...

  2. Spring 读取配置文件(一)

    注册 @Configuration 标识的类,spring 读取配置文件的时候该类会被自动装载 package cn.com.receive;import org.springframework.be ...

  3. java web路径和spring读取配置文件

    此篇博客缘起:部署java web系统到阿里云服务器(ubuntu14.04)的时候,有以下两个问题 找不到自定义的property配置文件 上传图片的时候找不到路径 开发的时候是在windows上的 ...

  4. CSharp读取配置文件的类(简单实现)

    Reinventing the wheel 系列 CSharp 读取配置文件的类 简单实现(注意没有写) 本人对CS 不是很熟,库也不熟,所以到网上找个实现,并自己添加了点异常.如果只是读取信息,足够 ...

  5. Spring读取配置文件 @Value

    最近在学习Spring如何读取配置文件,记录下方便自己也方便别人: 大致分为两类吧,一种的思路是利用Spring的beanFactoryPostProcessor读取配置文件内容到内存中,也就是应用程 ...

  6. Spring读取配置文件,获取bean的几种方式

    BeanFactory有很多实现类,通常使用 org.springframework.beans.factory.xml.XmlBeanFactory类.但对于大部分J2EE应用而言,推荐使 用App ...

  7. 关于spring读取配置文件的两种方式

    很多时候我们把需要随时调整的参数需要放在配置文件中单独进行读取,这就是软编码,相对于硬编码,软编码可以避免频繁修改类文件,频繁编译,必要时只需要用文本编辑器打开配置文件更改参数就行.但没有使用框架之前 ...

  8. Java中spring读取配置文件的几种方法

    Spring读取配置XML文件分三步: 一.新建一个Java Bean: package springdemo; public class HelloBean { private String hel ...

  9. Spring读取配置文件,地址问题,绝对路径,相对路径

    Spring在读取配置文件时,是相对于bin,或者WEB-INF的: “applicationContext.xml”就是找bin或WEB-INF及子文件夹下的文件: “/res/applicatio ...

随机推荐

  1. Tomcat集群环境下session共享方案 通过memcached 方法实现

    对于web应用集群的技术实现而言,最大的难点就是:如何能在集群中的多个节点之间保持数据的一致性,会话(Session)信息是这些数据中最重要的一块.要实现这一点, 大体上有两种方式:一种是把所有Ses ...

  2. errno , perror,strerror

    1. 简介 很多系统函数在错误返回时将错误原因记录在libc定义的全局变量errno中,每种错误原因对应一个错误码. errno在头文件errno.h中声明,是一个整型变量,所有错误码都是正整数. 然 ...

  3. js 修改css属性值

    js不能修改样式表 但是可以修改元素:比如 <div id="test" class="star-rating"></div> 对于上面 ...

  4. HDU 3726 Graph and Queries treap树

    题目来源:HDU 3726 Graph and Queries 题意:见白书 思路:刚学treap 參考白皮书 #include <cstdio> #include <cstring ...

  5. Intent传递对象的方法

    //传递对象 Bundle bundle = new Bundle(); intent = new Intent(getApplicationContext(), YourActivity.class ...

  6. linux最常用命令整理

    linux vim命令跳转到文档开头或末尾 gg:命令将光标移动到文档开头 G:命令将光标移动到文档末尾 <hr/> 网络 # ifconfig # 查看所有网络接口的属性 # iptab ...

  7. [Android] SQLite数据库之增删改查基础操作

        在编程中常常会遇到数据库的操作,而Android系统内置了SQLite,它是一款轻型数据库,遵守事务ACID的关系型数据库管理系统,它占用的资源非常低,可以支持Windows/Linux/Un ...

  8. c++中的对象复制

    (1)this指针 this是一个隐含于每个类的成员函数的特殊指针,该指针是一个指向正在被某个成员函数操作的对象的指针. 当一个对象调用成员函数时,编译程序先将对象的地址赋给this指针,也就是说,当 ...

  9. Android蓝牙开发

    Android蓝牙开发 近期做蓝牙小车,须要Android端来控制小车的运动.以此文记录开发过程. 使用HC-06无线蓝牙串口透传模块.对于其它的蓝牙设备本文相同适用. 蓝牙开发的流程: 获取本地蓝牙 ...

  10. STL源码剖析(deque)

    deque是一个双向开口的容器,在头尾两端进行元素的插入跟删除操作都有理想的时间复杂度. deque使用的是分段连续线性空间,它维护一个指针数组(T** map),其中每个指针指向一块连续线性空间. ...