spring配置文件中util:properties和context:property-placeholder
来源:互联网 发布:淘宝上的阿玛尼正品吗 编辑:程序博客网 时间:2024/06/06 06:39
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>
阅读全文
2 0
- spring配置文件中util:properties和context:property-placeholder
- context:property-placeholder和util:properties
- Spring properties context:property-placeholder
- Spring配置文件<context:property-placeholder>
- spring配置文件<context:property-placeholder>
- Spring的properties解析【context:property-placeholder】
- spring配置文件中<context:property-placeholder />的使用
- spring中context:property-placeholder
- spring中context:property-placeholder/
- spring配置文件中的context:property-placeholder属性
- spring配置文件中的context:property-placeholder属性
- 关于spring配置文件<context:property-placeholder>
- Spring配置文件<context:property-placeholder>标签使用
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- spring中context:property-placeholder/元素
- spring中context:property-placeholder/元素
- spring中context:property-placeholder/元素
- Banner 内存 磁盘 缓存
- 针对config.properties的配置文件读取的工具类
- Oracle学习笔记 -- day02 本机连接虚拟机(远程机)中的oracle设置
- SQL必知必会(2) 2~6课
- 360内核切换
- spring配置文件中util:properties和context:property-placeholder
- 蓝桥杯:01字串【水题】
- 3人3鬼过河问题
- [Robot OS]ROS机器人探索群资料列表(不定期更新)
- TabLayout
- 关于拼凑面额的动态规划算法
- opencv3学习之霍夫变换
- Query on a tree SPOJ
- MAC下pyenv和pyenv-virtualenv插件初探