1. 导入文件

  <import resource="applicationContext-dataSource.xml" />

2. 引用资源配置文件

<context:property-placeholder location="classpath:jdbc.properties,classpath:xxx.properties"/>
或者
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="xxx.properties" ignore-unresolvable="true"/>

  多次引用没有ignore-unresolvable="true"一定会出"Could not resolve placeholder"异常。

  Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,所以就不能使用上面的那种方法去配置,

  可以改如下的格式:

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/jdbc.properties</value>
</list>
</property>
</bean>

  使用引用的文件内容:

<bean name="userInfo" class="test.UserInfo">
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>

3. 在项目java代码中引用资源文件

  例如引用xxx.properties中的内容

  首先在spring容器中配置:

<util:properties id="settings" location="/WEB-INF/xxx.properties"></util:properties>

  java代码中使用方法:

@Value("#{settings}")
private Properties file;
或者
@Value("#{settings['test.abc']}")
private String url;

Spring容器管理各种文件的更多相关文章

  1. 如何在自定义Listener(监听器)中使用Spring容器管理的bean

    正好以前项目中碰到这个问题,现在网上偶然又看到这个问题的博文,那就转一下吧. 原文:http://blog.lifw.org/post/46428852 感谢作者 另外补充下:在web Server容 ...

  2. 为什么不在spring容器管理controller

    Spring容器与SpringMVC容器 1.疑问:为什么不用spring去管理所有类? 我们配置springMVC 中,为什么controller不直接交给spring 管理而要spring MVC ...

  3. 使用 Spring 容器管理 Filter

    当我们用Filter时,往往需要使用一些辅助的service,在普通的java中,只要声明(set,get方法)后在spring-application配置文件中配置就可以了,但是由于Filter与L ...

  4. 对Spring 容器管理事务支持的总结

    1.问题 Connection conn = DataSourceUtils.getConnection(); //开启事务 conn.setAutoCommit(false); try { Obje ...

  5. Spring容器 从XML 文件中读取bean的定义,并实例化bean?

    解释Spring框架中bean的生命周期. Spring根据bean的定义填充所有的属性. 如果bean实现了BeanNameAware 接口,Spring 传递bean 的ID 到 setBeanN ...

  6. Spring加载applicationContext.xml实现spring容器管理的单例模式

    package com.etc.pojo; import org.springframework.context.ApplicationContext; import org.springframew ...

  7. Spring加载applicationContext.xml实现spring容器管理的几种方式

    package com.etc.test; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; i ...

  8. Spring管理Filter和Servlet(在servlet中注入spring容器中的bean)

    在使用spring容器的web应用中,业务对象间的依赖关系都可以用context.xml文件来配置,并且由spring容器来负责依赖对象 的创建.如果要在servlet中使用spring容器管理业务对 ...

  9. 【Java EE 学习 52】【Spring学习第四天】【Spring与JDBC】【JdbcTemplate创建的三种方式】【Spring事务管理】【事务中使用dbutils则回滚失败!!!??】

    一.JDBC编程特点 静态代码+动态变量=JDBC编程. 静态代码:比如所有的数据库连接池 都实现了DataSource接口,都实现了Connection接口. 动态变量:用户名.密码.连接的数据库. ...

随机推荐

  1. nginx 知识

    nginx如何实现高并发? 启动nginx服务器后,输入 ps -ef |grep nginx,会发现nginx有一个master进程 和若干个worker进程, 这些worker进程是平等的,都是被 ...

  2. for循环和字典预习

    print("*" *8)for a in range(1,9): print(a,end="")#1-9的奇数print()for a in range(1, ...

  3. 重装系统后配置原有的mysql

    1.重装系统后配置原有的mysql 2.修改 my.ini [修改 basedir:MySQL当前所在路径 datadir  数据存放路径] [mysqld] # 设置3306端口 port= # 设 ...

  4. [CTSC2018]青蕈领主

    [CTSC2018]青蕈领主 题解 首先,连续段要知道结论: 连续段要么不交,要么包含 所以是一棵树!每个位置的father是后面第一个包含它的 树形DP! 设dp[x],x为根的子树,(设管辖的区间 ...

  5. (转)自定义ClassLoader ----可以加载第三方jar包

    package com.classloader.util; import java.io.IOException; import java.net.MalformedURLException; imp ...

  6. VS2010-MFC(状态栏的使用详解)

    转自:http://www.jizhuomi.com/software/219.html 上一节讲了工具栏的创建.停靠与使用,本节来讲解状态栏的知识. 状态栏简介 状态栏相信大家在很多窗口中都能见到, ...

  7. VI/VIM 无法使用系统剪贴板(clipboard)

    来自: http://www.bubuko.com/infodetail-469867.html vim 系统剪贴板 "+y 复制到系统剪切板 "+p 把系统粘贴板里的内容粘贴到v ...

  8. Integer 类和 int 基本数据类型的区别

    public static void main(String[] args) { Integer i = 10; Integer j = 10; System.out.println(i == j); ...

  9. java中字符数组与字符串之间互相转换的方法

    public static void main(String[] args) { //1.字符数组 转换成 字符串 //(1)直接在构造String时转换 char[] array = new cha ...

  10. vue+el-menu+vue-router实现动态导航条

    导航栏组件template <template> <div class="sidebar"> <el-menu unique-opened :defa ...