- 浏览: 1040716 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (501)
- dwr (6)
- javascript (84)
- oracle (66)
- jsp/servlet (18)
- ant (3)
- 基础知识 (12)
- EXT (10)
- My SQL (10)
- java (71)
- spring (37)
- 学习的对象 (2)
- Linux (24)
- 面试 (1)
- HTML/CSS (11)
- tomcat (11)
- 收藏夹 (2)
- Power Designer (2)
- struts.xml配置文件 (1)
- sturts2 (3)
- myeclipse (8)
- eclipse (7)
- Maven (34)
- SVN (3)
- SAP JCO (2)
- JBOSS (11)
- webservice (8)
- word (1)
- 敏捷开发 (1)
- sybase (4)
- Nexus (3)
- EhCache (3)
- log4j (3)
- Cookie (4)
- Session (4)
- CXF (7)
- AXIS (2)
- SSO (1)
- LDAP (1)
- velocity (2)
- Jquery (5)
- redis (2)
- http (4)
- dojo (1)
- Linux资源监控软件mnon的安装与运用 (1)
- notepad++ (1)
- EA (1)
- UML (1)
- JasperReports (1)
- 权限 (0)
- freemarker (4)
- Spring MVC (1)
- JMS (1)
- activeMQ (1)
- hession (3)
- 安全 (1)
- ibatis (2)
- log (1)
- nginx (1)
最新评论
-
winhbb:
我刚好遇到了一个问题(在可以依赖注入的场合有效):有两个模块A ...
解决Maven项目相互依赖/循环依赖/双向依赖的问题 -
nanjiwubing123:
long3ok 写道你好 XmlOutputFormatter ...
用XStream转换复杂XML -
zhoujianboy:
另外一个方法实现eclipse tomcat 热部署:http ...
eclipse下实现maven项目在tomcat容器热部署方法 -
long3ok:
你好 XmlOutputFormatter 请问这个类是在什么 ...
用XStream转换复杂XML -
ganbo:
总结的好,文章给力。
解决Maven项目相互依赖/循环依赖/双向依赖的问题
Spring 利用PropertyPlaceholderConfigurer占位符
1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFactoryPostProcessor接口的一个实现。PropertyPlaceholderConfigurer可以将上下文(配置文件)中的属性值放在另一个单独的标准java Properties文件中去。在XML文件中用${key}替换指定的properties文件中的值。这样的话,只需要对properties文件进行修改,而不用对xml配置文件进行修改。
2.在Spring中,使用PropertyPlaceholderConfigurer可以在XML配置文件中加入外部属性文件,当然也可以指定外部文件的编码,如:
3.譬如,jdbc.properties的内容为:
4.那么在spring配置文件中,我们就可以这样写:
5.这样,一个简单的数据源就设置完毕了。可以看出:PropertyPlaceholderConfigurer起的作用就是将占位符指向的数据库配置信息放在bean中定义的工具。
6.查看源代码,可以发现,locations属性定义在PropertyPlaceholderConfigurer的祖父类PropertiesLoaderSupport中,而location只有 setter方法。类似于这样的配置,在spring的源程序中很常见的。
PropertyPlaceholderConfigurer如果在指定的Properties文件中找不到你想使用的属性,它还会在Java的System类属性中查找。
我们可以通过System.setProperty(key, value)或者java中通过-Dnamevalue来给Spring配置文件传递参数。
【转载地址】http://www.cnblogs.com/yl2755/archive/2012/05/06/2486752.html
配置文件位于外部目录
但是对于外部目录的配置文件,使用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer也是可以加载的,不过要修改他的路径配置方式,如下:
这样就可以成功加载外部目录的配置文件了,${user.dir}是系统变量,指用户当前目录所在。
1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFactoryPostProcessor接口的一个实现。PropertyPlaceholderConfigurer可以将上下文(配置文件)中的属性值放在另一个单独的标准java Properties文件中去。在XML文件中用${key}替换指定的properties文件中的值。这样的话,只需要对properties文件进行修改,而不用对xml配置文件进行修改。
2.在Spring中,使用PropertyPlaceholderConfigurer可以在XML配置文件中加入外部属性文件,当然也可以指定外部文件的编码,如:
<bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>conf/sqlmap/jdbc.properties</value> </property> <property name="fileEncoding"> <value>UTF-8</value> </property> </bean> 当然也可以引入多个属性文件,如: <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/WEB-INF/mail.properties</value> <value>classpath: conf/sqlmap/jdbc.properties</value>//注意这两种value值的写法 </list> </property> </bean>
3.譬如,jdbc.properties的内容为:
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost/mysqldb?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=round; jdbc.username=root jdbc.password=123456
4.那么在spring配置文件中,我们就可以这样写:
<bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath: conf/sqlmap/jdbc.properties </value> </list> </property> </bean> <bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"> <property name="driverClassName"value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}"/> <property name="password"value="${jdbc.password}" /> </bean>
5.这样,一个简单的数据源就设置完毕了。可以看出:PropertyPlaceholderConfigurer起的作用就是将占位符指向的数据库配置信息放在bean中定义的工具。
6.查看源代码,可以发现,locations属性定义在PropertyPlaceholderConfigurer的祖父类PropertiesLoaderSupport中,而location只有 setter方法。类似于这样的配置,在spring的源程序中很常见的。
PropertyPlaceholderConfigurer如果在指定的Properties文件中找不到你想使用的属性,它还会在Java的System类属性中查找。
我们可以通过System.setProperty(key, value)或者java中通过-Dnamevalue来给Spring配置文件传递参数。
【转载地址】http://www.cnblogs.com/yl2755/archive/2012/05/06/2486752.html
配置文件位于外部目录
但是对于外部目录的配置文件,使用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer也是可以加载的,不过要修改他的路径配置方式,如下:
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>file:${user.dir}/config/init.properties</value> <value>file:${user.dir}/config/init2.properties</value> </list> </property> </bean>
这样就可以成功加载外部目录的配置文件了,${user.dir}是系统变量,指用户当前目录所在。
发表评论
-
Spring MVC 3.1新特性 生产者、消费者请求限定
2015-06-15 07:42 669参考地址: http://www.iteye.com/to ... -
CSRF TOKEN
2015-02-14 18:02 1109package com.uncle5.pubrub.web.c ... -
Spring MVC Controller单例陷阱
2014-06-27 08:51 643Spring MVC Controller默认是 ... -
[Spring] Hessian权限认证,加密前面
2014-03-06 09:52 1571Hessian的一些基本简介已经在上一节已经全部介绍了,上一节 ... -
FieldRetrievingFactoryBean 和 MethodInvokingFactoryBean
2014-01-09 18:36 982spring提供了filed的值注入和method的返回值注入 ... -
Spring中ApplicationContext的事件机制(二 内定事件)
2014-01-09 11:08 12285在Spring中已经定义了五个标准事件,分别介绍如下: 1) ... -
当spring 容器初始化完成后执行某个方法 .
2014-01-08 17:40 1399在某些应用中,我们希望,当spring 容器将所有的bea ... -
spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
2013-09-12 10:43 1169spring mvc处理方法支持如下的返回方式:ModelA ... -
JSR-303
2013-09-12 00:22 893JSR-303 是JAVA EE 6 中的一项子规范,叫做Be ... -
EHCACHE分布式缓存
2013-09-06 17:26 1272从1.2版本开始,Ehcache可 ... -
springMVC+freemarker整合
2013-09-06 16:39 1384springMVC整合大家都比较熟悉了吧主要有以下几个步骤: ... -
Spring MVC 学习笔记 Viewresol和View
2013-09-06 15:34 894Spring MVC使用ViewResolver来根据cont ... -
SpringSecurity3_Logout
2013-08-22 16:07 2541Logout¶•退出登录的链接 <a href=&quo ... -
spring的default-lazy-init参数 .
2013-04-23 20:08 951spring在启动的时候,会默认加载会默认加载整个对象实例图, ... -
Spring MVC 如何防止XSS、SQL注入攻击
2013-04-16 15:40 1632在Web项目中,通常需要处理XSS,SQL注入攻击,解决这个问 ... -
Spring JMS
2013-01-08 10:48 919http://blog.csdn.net/shiqiang12 ... -
给spring jdbctemplate加上一层“绮丽外衣”-动态SQL&&SQL语句以文件存放
2013-01-07 16:00 3272给spring jdbctemplate加上一层“华丽外衣”- ... -
使用Spring的NamedParameterJdbcTemplate完成DAO操作 .
2013-01-07 14:54 1141NamedParameterJdbcTemplate内部包含了 ... -
cron表达式(quartz中时间表达式)
2012-12-20 15:54 910http://sosuny.iteye.com/blog/46 ... -
spring 3中新增的@value注解
2012-11-26 22:31 3352在spring 3.0中,可以通过使用@value,对一些如x ...
相关推荐
Spring中PropertyPlaceholderConfigurer的使用
NULL 博文链接:https://wokeke.iteye.com/blog/2214113
Spring属性占位符PropertyPlaceholderConfigurer的使用,自己写的一个demo
主要介绍了Spring如何使用PropertyPlaceholderConfigurer读取文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序。它提供了很多方面的功能,比如依赖注入、面向方面编程(AOP)、数据访问抽象及ASP.NET扩展等等。Spring.NET以Java版的Spring框架为...
管理 Bean 从第一个 Spring 应用程式开始,逐步了解何谓依赖注入,以及如何使用 Spring 的容器功能来管理 Bean,了解 Bean 在 Spring 容器中的生命周期。 第一个 Spring 程式 BeanFactory、 ...
6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点实施 7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入...
6 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 7 8 9 <value>/WEB-INF/jdbc.properties 10 11 12 13 14 它配置了以下功能: 读取...
NULL 博文链接:https://chyy001.iteye.com/blog/1338488
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面...<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath:proxool.properties ...
4.6.1.6 在非Web 应用中,优雅地关闭Spring IoC 容器 74 4.6.2 ApplicationContextAware 和BeanNameAware . 75 4.6.3 其它Aware 接口 75 4.7 Bean 定义的继承. 77 4.8 容器扩展点. 78 4.8.1...
#Spring 属性注释扩展的 PropertyPlaceHolderConfigurer 使用注解将配置属性注入到 Spring 组件中。 注意:Spring 3 现在支持使用 @Value 注释的容器的。 该项目仅用于 Spring 2.5.x 支持。 ##入门Spring房产注解...
PropertyPlaceholderConfigurer PropertyResourceConfigurer PropertyValue PropertyValues PropertyValuesEditor PrototypeAspectInstanceFactory PrototypeTargetSource ProxyConfig ProxyFactory ...
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>WEB-INF/jdbc.properties class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-...
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
spring3.1中文参考文档,南磊翻译,现在有4章,目录如下: 第一部分 Spring framework概述.......................................................................................................................
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <value>classpath*:jdbc.properties <!-- 数据源配置,主要用于开发测试...
JDBCTemp+MySQL示例。Spring,PropertyPlaceholderConfigurer,BeanPropertyRowMapper
什么 与通过从属性文件读取其配置来进行自我配置相比,对于应用程序而言,有什么可能更简单? 好吧,对于业务应用程序而言... 首先,我们将使用PropertyPlaceholderConfigurer通过读取存储在.properties文件中的属性来