applicationContext.xml中的使用${}是代表什么意思?
在applicationContext.xml文件中,使用 ${xxx} 表示的是:调用某个变量,该变量的名称就是{xxx}里面的"xxx"。
<!-- 配置数据链接池 -->
<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>
jdbcUrl=jdbc:mysql://localhost:3306/oa
driverClass=com.mysql.jdbc.Driver
user=root
password=
-------2016-10-11 更新---
那么该如何引入properties文件呢?在哪里进行引入?
一般情况下,如果你只有一个applicationContext.xml配置文件而已的话,那么只需要在applicationContext.xml文件中添加一行:
<!-- 导入外部的properties文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<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中的使用${}是代表什么意思?的更多相关文章
- spring controller中@Value取不到applicationContext.xml中加载配置文件的问题
原因还未查证: http://sunjun041640.blog.163.com/blog/static/256268322014127113844746/ 在使用spring mvc时,实际上是两个 ...
- SSH整合,applicationContext.xml中配置hibernate映射文件问题
今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...
- applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.
我用的jeesite框架,在使用定时任务时,出现一些问题,,1.在windows上项目可以在tomcat下,运行2.在linux下项目在tomcatgh下,却出现问题: 15-Dec-2017 15: ...
- 在application-context.xml中配置多个property-placeholder
如下所示,直接写多个<context:property-placeholder>标签是会报错的. <context:property-placeholder location=&qu ...
- spring applicationContext.xml中<beans>中属性概述
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- spring applicationContext.xml 中bean配置
如果采用set get方法配置bean,bean需要有set get 方法需要有无参构造函数,spring 在生成对象时候会调用get和set方法还有无参构造函数 如果采用constructor方法则 ...
- spring的applicationContext.xml中的DBCP配置如下:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy ...
- 如果在applicationContext.xml中没有配置bean的属性,那么也会导致空指针异常
报错如下: java.lang.NullPointerException cn.itcast.action.VisitAction.toAddPage(VisitAction.java:37) sun ...
- Spring,SpringMvc配置常见的坑,注解的使用注意事项,applicationContext.xml和spring.mvc.xml配置注意事项,spring中的事务失效,事务不回滚原因
1.Spring中的applicationContext.xml配置错误导致的异常 异常信息: org.apache.ibatis.binding.BindingException: Invalid ...
随机推荐
- Git 简史
同生活中的许多伟大事件一样,Git 诞生于一个极富纷争大举创新的年代.Linux 内核开源项目有着为数众广的参与者.绝大多数的 Linux 内核维护工作都花在了提交补丁和保存归档的繁琐事务上(1991 ...
- Java 集合补充
集合大致可以分List,Set,Queue,Map四种体系. 集合和数组不一样,数组元素可以是基本类型的值,也可以是对象(的引用变量),集合里只能保存对象(的引用变量). 访问:如果访问List集合中 ...
- hdu-4027线段树练习
title: hdu-4027线段树练习 date: 2018-10-10 18:07:11 tags: acm 算法 刷题 categories: ACM-线段树 # 概述 这道线段树的题可以说是我 ...
- Entity Framework Core介绍(1)
介绍 Entity Framework (EF) Core 是轻量化.可扩展和跨平台版的常用 Entity Framework 数据访问技术. EF Core 可用作对象关系映射程序 (O/RM),以 ...
- iOS Sprite Kit教程之使用帮助文档以及调试程序
iOS Sprite Kit教程之使用帮助文档以及调试程序 IOS中使用帮助文档 在编写代码的时候,可能会遇到很多的方法.如果开发者对这些方法的功能,以及参数不是很了解,就可以使用帮助文档.那么帮助文 ...
- 再谈应用环境下的TIME_WAIT和CLOSE_WAIT
昨天解决了一个HttpClient调用错误导致的服务器异常,具体过程如下: http://blog.csdn.net/shootyou/article/details/6615051 里头的分析过程有 ...
- tftp协议
<前言> 嵌入式开发是一个交叉开发的模式,需要将宿主机上的文件烧写到目标机上. 方式: JTAG USB 串口 网络 <tftp下载> 首先需要将宿主机架成一个TFTP的服务器 ...
- window.open()/剪切板ZeroClipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- UC浏览器 垂直水平居中
今天使用下述方式定义水平垂直居中不起作用 #box{ position: fixed; left:; right:; top:; bottom:; margin: auto; } 然后改用: #box ...
- Codeforces Beta Round #97 (Div. 1) C. Zero-One 数学
C. Zero-One 题目连接: http://codeforces.com/contest/135/problem/C Description Little Petya very much lik ...