在applicationContext.xml文件中,使用 ${xxx} 表示的是:调用某个变量,该变量的名称就是{xxx}里面的"xxx"。

 
例如:在applicationContext.xml文件中配置数据连接池
  1. <!-- 配置数据链接池 -->
    <propertyname="dataSource">
    <beanclass="com.mchange.v2.c3p0.ComboPooledDataSource">
    <propertyname="jdbcUrl"value="${jdbcUrl}"></property>
    <propertyname="driverClass"value="${driverClass}"></property>
    <propertyname="user"value="${user}"></property>
    <propertyname="password"value="${password}"></property>
    <!-- 其它配置 -->
    <!-- 初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default:3 -->
    <propertyname="initialPoolSize"value="3"></property>
    <!-- 连接池中保留的最小连接数。Default:3 -->
    <propertyname="minPoolSize"value="3"></property>
    <!-- 连接池中保留的最大连接数。Default:15 -->
    <propertyname="maxPoolSize"value="15"></property>
    <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default:3 -->
    <propertyname="acquireIncrement"value="3"></property>
    <!--
    控制数据源内加载preparedStatement数量.如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:0
    -->
    <propertyname="maxStatements"value="8"></property>
    <!--
    maxStatementsPerConnection 定义了连接池内单个连接所拥有的最大缓存statements数。Default:0
    -->
    <propertyname="maxStatementsPerConnection"value="5"></property>
    <!-- 最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default:0 -->
    <propertyname="maxIdleTime"value="1800"></property>
    </bean>
    </property>
代码中被标识的部分就是使用了${}的功能。它相当于Java中调用了变量名一样。
在本例子中,这些变量来自另外一个properties文件。该properties为: jdbc.properties(主要用来存放JDBC连接数据库的一些配置,方便下次修改,而不需要在applicationContext.xml文件中修改。)
jdbc.properties:
  1. jdbcUrl=jdbc:mysql://localhost:3306/oa
    driverClass=com.mysql.jdbc.Driver
    user=root
    password=
${jdbcUrl} 中的jdbcUrl 指的就是jdbc.properties中jdbcUrl。

-------2016-10-11 更新---

那么该如何引入properties文件呢?在哪里进行引入?

一般情况下,如果你只有一个applicationContext.xml配置文件而已的话,那么只需要在applicationContext.xml文件中添加一行:

<!-- 导入外部的properties文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
其中:location属性是指该文件的位置。
如果是在src目录下的话,该位置为:classpath:文件名.后缀
如果是在/WEB-INF/目录下的话,该位置为: /WEB-INF/文件名.后缀。
但是要注意,不要放错位置了,<context:property-placeholder>不能发到<bean></bean>标签里面去。否则会报错;
 
说说:<context:property-placeholder/>的配置,内容好像是来自开涛博客,具体链接不知道了。
<context:property-placeholder/>配置如下:
<context:property-placeholder
location="属性文件,多个之间逗号分隔"
file-encoding="文件编码"
ignore-resource-not-found="是否忽略找不到的属性文件"
ignore-unresolvable="是否忽略解析不到的属性,如果不忽略,找不到将抛出异常"
properties-ref="本地Properties配置"
local-override="是否本地覆盖模式,即如果true,那么properties-ref的属性将覆盖location加载的属性,否则相反"
system-properties-mode="系统属性模式,默认ENVIRONMENT(表示先找ENVIRONMENT,再找properties-ref/location的),NEVER:表示永远不用ENVIRONMENT的,OVERRIDE类似于ENVIRONMENT"
order="顺序"
/>

location:表示属性文件位置,多个之间通过如逗号/分号等分隔;

file-encoding:文件编码;

ignore-resource-not-found:如果属性文件找不到,是否忽略,默认false,即不忽略,找不到将抛出异常

ignore-unresolvable:是否忽略解析不到的属性,如果不忽略,找不到将抛出异常

properties-ref:本地java.util.Properties配置

local-override:是否本地覆盖模式,即如果true,那么properties-ref的属性将覆盖location加载的属性

system-properties-mode:系统属性模式,ENVIRONMENT(默认),NEVER,OVERRIDE

ENVIRONMENT:将使用Spring 3.1提供的PropertySourcesPlaceholderConfigurer,其他情况使用Spring 3.1之前的PropertyPlaceholderConfigurer

如果是本地覆盖模式:那么查找顺序是:properties-ref、location、environment,否则正好反过来;

OVERRIDE: PropertyPlaceholderConfigurer使用,因为在spring 3.1之前版本是没有Enviroment的,所以OVERRIDE是spring 3.1之前版本的Environment

如果是本地覆盖模式:那么查找顺序是:properties-ref、location、System.getProperty(),System.getenv(),否则正好反过来;

NEVER:只查找properties-ref、location;

order:当配置多个<context:property-placeholder/>时的查找顺序,关于顺序问题请参考:http://www.iteye.com/topic/1131688

具体使用请参考如下文件中的如dataSource:

https://github.com/zhangkaitao/es/blob/master/web/src/main/resources/spring-config.xml

applicationContext.xml中的使用${}是代表什么意思?的更多相关文章

  1. spring controller中@Value取不到applicationContext.xml中加载配置文件的问题

    原因还未查证: http://sunjun041640.blog.163.com/blog/static/256268322014127113844746/ 在使用spring mvc时,实际上是两个 ...

  2. SSH整合,applicationContext.xml中配置hibernate映射文件问题

    今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...

  3. applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.

    我用的jeesite框架,在使用定时任务时,出现一些问题,,1.在windows上项目可以在tomcat下,运行2.在linux下项目在tomcatgh下,却出现问题: 15-Dec-2017 15: ...

  4. 在application-context.xml中配置多个property-placeholder

    如下所示,直接写多个<context:property-placeholder>标签是会报错的. <context:property-placeholder location=&qu ...

  5. spring applicationContext.xml中<beans>中属性概述

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...

  6. spring applicationContext.xml 中bean配置

    如果采用set get方法配置bean,bean需要有set get 方法需要有无参构造函数,spring 在生成对象时候会调用get和set方法还有无参构造函数 如果采用constructor方法则 ...

  7. spring的applicationContext.xml中的DBCP配置如下:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy ...

  8. 如果在applicationContext.xml中没有配置bean的属性,那么也会导致空指针异常

    报错如下: java.lang.NullPointerException cn.itcast.action.VisitAction.toAddPage(VisitAction.java:37) sun ...

  9. Spring,SpringMvc配置常见的坑,注解的使用注意事项,applicationContext.xml和spring.mvc.xml配置注意事项,spring中的事务失效,事务不回滚原因

    1.Spring中的applicationContext.xml配置错误导致的异常 异常信息: org.apache.ibatis.binding.BindingException: Invalid ...

随机推荐

  1. MySQL 大数据量使用limit分页,随着页码的增大,查询效率越低下。

    数据表结构 CREATE TABLE `ad_keyword` ( `id` int(11) NOT NULL AUTO_INCREMENT, `plan_goods_id` int(11) DEFA ...

  2. Java 关于集合框架那点事儿

     1.引入集合框架  采用数组存在的一些缺陷:   1.数组长度固定不变,不能很好地适应元素数量动态变化的情况.   2.可通过数组名.length获取数组的长度,却无法直接获取数组中真实存储的个数. ...

  3. iOS Sprite Kit教程之xcode安装以及苹果帐号绑定

    iOS Sprite Kit教程之xcode安装以及苹果帐号绑定 其它的网站上下载安装Xcode 有时候,应用商店下载较慢,所以用户也可以选择从其他网站下载Xcode安装文件.下面讲解这种Xcode的 ...

  4. 【BZOJ 3470】3470: Freda’s Walk 期望

    3470: Freda’s Walk Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 42  Solved: 22 Description 雨后的Poet ...

  5. 利用meterpreter下的Venom免杀后门

    转载请注明作者:admin-神风 下载地址:https://github.com/r00t-3xp10it/venom .从Github上下载框架: tar.gz OR zip OR git clon ...

  6. Android之安全机制

    根据android四大框架来解说安全机制 代码安全 java不同于C/C++,java是解释性语言,存在代码被反编译的隐患: 默认混淆器为proguard,最新版本为4.7: proguard还可用来 ...

  7. python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐

    在了解python中的tkinter模块的时候,你需要了解一些tkinter的相关知识 下面是python的API文档中的一个简单例子: import tkinter as tk class Appl ...

  8. SGU 404 Fortune-telling with camomile

    404. Fortune-telling with camomile Time limit per test: 0.25 second(s)Memory limit: 65536 kilobytes ...

  9. URAL 1881 Long problem statement

    1881. Long problem statement Time limit: 0.5 secondMemory limit: 64 MB While Fedya was writing the s ...

  10. EXPLAIN 用法

    重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...