spring配置文件中util:properties和context:property-placeholder
util:properties和context:property-placeholder标签都可以用来获取外部配置文件中的内容
1、util:properties
它是以声明bean方式来使用,创建了一个bean,下面使用的时候通过SpEL表达式#{}获取bean的属性。
<util:properties id="config" location="classpath:db.properties" />
<!-- 配置连接池 -->
<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="#{config.driver}" />
<property name="url" value="#{config.url}" />
<property name="username" value="#{config.username}" />
<property name="password" value="#{config.password}" />
</bean>
需要注意,这种方式需要在spring配置文件头部声明
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"
2、context:property-placeholder
它是将配置文件加载至spring上下文中,然后通过${}取得值,常用于bean的属性上
<context:property-placeholder location="classpath:general.properties"/>
<!-- 配置Druid连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- 基本属性 driverClassName、url、user、password -->
<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>
spring配置文件中util:properties和context:property-placeholder的更多相关文章
- 配置文件中取值: spring配置文件中util:properties和context:property-placeholder
转载大神 https://blog.csdn.net/n447194252/article/details/77498916 util:properties和context:property-plac ...
- spring 配置文件中使用properties文件 配置
配置Bean载入properties文件: <bean id="propertyPlaceholderConfigurer" class="org.springfr ...
- Spring依赖注入的方式、类型、Bean的作用域、自动注入、在Spring配置文件中引入属性文件
1.Spring依赖注入的方式 通过set方法完成依赖注入 通过构造方法完成依赖注入 2.依赖注入的类型 基本数据类型和字符串 使用value属性 如果是指向另一个对象的引入 使用ref属性 User ...
- Spring 源码(4)在Spring配置文件中自定义标签如何实现?
Spring 配置文件自定义标签的前置条件 在上一篇文章https://www.cnblogs.com/redwinter/p/16165274.html Spring BeanFactory的创建过 ...
- 在spring配置文件中引入外部properties配置文件 context:property-placeholder
在spring的配置文件中,有时我们需要注入很多属性值,这些属性全都写在spring的配置文件中的话,后期管理起来会非常麻烦.所以我们可以把某一类的属性抽取到一个外部配置文件中,使用时通用spring ...
- 通过Spring配置文件中bean中的property赋值
基本数据类型赋值-通过spring配置文件中bean中的property 扩展-以此方式可以通过配置为连接数据的属性赋值 1.如果是基本数据类型,可以通过setter方法为对象中的属性设置初始值,应用 ...
- JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
JdbcTemplate的使用 Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调. JdbcTemplate 简化 JDBC 操作HibernateTemplate 简化 Hiber ...
- Spring配置文件中的parent与abstract
在看项目的Spring配置文件时,发现消息队列的配置采用了继承方式配置Bean,在这梳理总结一下. 其实在基于spring框架开发的项目中,如果有多个bean都是一个类的实例,如配置多个数据源时,大部 ...
- Spring bean中的properties元素内的name 和 ref都代表什么意思啊?
<bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" sc ...
随机推荐
- R: 正则表达式
正则表达式: 例:sub("a","",c("abcd","dcba")): [1] "bcd" ...
- Python程序设计6——面向对象
面向对象有三大特征:多态(对应方法覆写).封装.继承(对应方法重载),这个在Java中已经说得很详细了,这里面只是介绍Python在这三个特性方面的实现. 1 创建自定义类 Python和Java一样 ...
- format Code
setting中设置format code. 方便格式化代码.
- Python-第三方库requests详解(附requests中文官方教程)
转自http://blog.csdn.net/cyjs1988/article/details/73294774 Python+requests中文官方教程: http://www.python-re ...
- 比较get 和post
- C#中如何防止Excel做科学计算法转换
C#中如何防止Excel做科学计算法转换 string style = @"<style>.text{mso-number-format:\@;}</style>& ...
- css实现点点点效果
@keyframes dotDotDoting{ 0% { width 0px margin-right 15px } 25% { width 0px margin-right 15px } 50% ...
- nginx 简单教程
使用 nginx 的使用比较简单,就是几条命令. 常用到的命令如下: nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务. nginx -s quit 平稳关闭N ...
- 阅读GFS的一点总结
这是我第一次阅读学术论文,文章中充斥的一些学术名词给我的阅读带来了一些困难,因为此前没有接触过这方面的内容,在同学的帮助下,查阅了一些资料,终于对GFS有了一点认识,写出这一些感悟,文章措辞不严谨之处 ...
- Codeforces Round #534 (Div. 2) D. Game with modulo 交互题
先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...