首先在配置文件中配置PropertyPlaceholderConfigurer

单个配置文件: 
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  <property name="locations" value="classpath:com/foo/jdbc.properties"/>  
</bean>  
多个配置文件: 
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
  <property name="locations"> 
    <list>            
        <value>classpath:jdbc.properties</value> 
        <value>classpath:config.properties</value> 
   </list>
</property> 
</bean>

然后在需要的地方直接以下方式引用: 
<property name="url" value="${jdbc.url}"/>

spring读取properties的方法的更多相关文章

  1. 如何通过Spring读取Properties文件

    1 在Spring中配置文件中, 配置配置文件的引用     <util:properties id="settings" location="/WEB-INF/c ...

  2. spring 读取properties文件--通过注解方式

    问题: 需要通过properties读取页面的所需楼盘的名称.为了以后便于修改. 解决: 可以通过spring的 PropertiesFactoryBean 读取properties属性,就不需要自己 ...

  3. Java-马士兵设计模式学习笔记-工厂模式-模拟Spring读取Properties文件

    一.目标:读取properties文件,获得类名来生成对象 二.类 1.Movable.java public interface Movable { void run(); } 2.Car.java ...

  4. spring 读取properties的两种方法

    一:直接使用context命名空间 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi= ...

  5. Spring: 读取 .properties 文件地址,json转java对象,el使用java类方法相关 (十三)

    1. 在Java中获取 .properties 文件的路径 (src/main/resources 下) ProjectName |---src/main/java |---src/main/reso ...

  6. Spring读取properties资源文件

    我们知道可以通过读取资源文件流后加载到Properties对象,再使用该对象方法来获取资源文件.现在介绍下利用Spring内置对象来读取资源文件. 系统启动时加载资源文件链路:web.xml --&g ...

  7. spring读取properties和其他配置文件的几种方式

    1.因为spring容器的一些机制,在读取配置文件进行数据库的配置等等是很有必要的,所以我们要考虑配置文件的的读取方式以及各个方式的实用性 2.配置文件的读取方式我这里介绍2种,目的是掌握这2种就可以 ...

  8. java读取properties配置文件方法(一)

    为了修改项目参数方便,需要使用properties配置文件: 首先是需要三个jar包(不同的jar包,读取配置文件的方式会有所不同,这里使用的是2.6版本的jar包) commons configur ...

  9. @Schedule注解中的Cron表达式读取properties的方法

    1.properties文件中增加配置项: datasync.cron=0 */10 * * * ? 2.定时任务类增加PropertySource注解: @PropertySource(" ...

随机推荐

  1. Java 小片段

    public static String listToString(List<String> stringList){ if (stringList==null) { return nul ...

  2. Android ViewPager欢迎页+引导页+进入首页

    import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences ...

  3. ubuntu下安装selenium2.0 环境

    参考:http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html ubuntu 安装过程: 1.安装:setuptools $ apt-ge ...

  4. The Tower of Babylon

    题意: 有n个,长x宽y高z的长方体,把这些长方体摞起来,上面长方体底面的长宽一定要小于下面的,求能摞的最大高度. 分析: 一个长方体,可以有三种放法,先把所有放的状态存起来,按底面升序排列,dp[i ...

  5. andriod的简单用法2

    1.在Activity中使用menu //创建菜单项 public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this ...

  6. Dictionary<实体,List<实体>>的比较

    当Dictionary中Key为实体时,进行用ContainsKey比较会发现,就算Model为一样但是结果比较为不存在: 故用以下代码即可,现将Keys转换ToArray(),再用数组的Contai ...

  7. Java中的return

    比如你写了一个叫getInt的类public int getInt(){ //这个类的意思就是一个具有返回值类型为int的类了 //通常如果不需要返回值的话 这里就写void....//你的具体代码r ...

  8. 瞬间从IT屌丝变大神——分工安排

    分工安排主要包含以下内容: 公共组件(包括common.css和common.js)一人维护,各子频道专人负责,每个频道正常情况下由一人负责,要详细写明注释,如多人合作,维护的人员注意添加注释信息,具 ...

  9. web.py网页模板中使用jquery

    由于$是web.py针对模板的保留字符,所以在模板文件内不能直接使用$("#id")的格式. 解决办法: 1.$$("#id")可以避免$被误解析 2.jque ...

  10. spice

    the following diagram illustrates VD-Interface illustrates display portemphasizing   emphasizing   e ...