配置文件中取值: spring配置文件中util:properties和context:property-placeholder
转载大神
https://blog.csdn.net/n447194252/article/details/77498916
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的更多相关文章
- Oracle---------sql 中取值两列中值最大的一列
1.表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列. select (case when a>b then a else b ...
- spring配置文件中util:properties和context:property-placeholder
util:properties和context:property-placeholder标签都可以用来获取外部配置文件中的内容 1.util:properties 它是以声明bean方式来使用,创建了 ...
- Mybatis映射文件中#取值时指定参数相关规则
Mybatis映射文件中#取值时指定参数相关规则 在#{}中,除了需要的数值外,还可以规定参数的一些其他规则. 例如:javaType,jdbcType,mode(存储过程),numericScale ...
- 从cookie中取值$.cookie()
从cookie中取值: var userid = $.cookie("remoteuserid");例子: function delUser() { var table = ...
- layui从url中取值 ajax获取当前链接中的变量
在使用layui(javascript)的时候, 需要从当前页面的url地址中取值, 例如: http://localhost:8081/html/fund-purchase.html?fundID ...
- XML配置文件的命名空间与Spring配置文件中的头
一直以来,写Spring配置文件,都是把其他配置文件的头拷贝过来,最多改改版本号,也不清楚哪些是需要的,到底是干嘛的.今天整理一下,拒绝再无脑copy. 一.Spring配置文件常见的配置头 < ...
- Spring MVC-从零开始-@RequestMapping结合@PathVariable (从URL路径中取值,作用于函数参数)
1.可以直接在RequestMapping中value元素中使用{key}描述属性键 2.也可以在{key}中使用正则限定key的取值范围,从而限定url的变化范围 package com.jt; i ...
- Spring-Boot导入配置文件与取值
前言: springboot简化了大量配置文件,但是必要时还是需要导入配置文件的,比如dubbo,此处简记之. 正文: 所有的配置文件引入都是使用注解在类上进行引入的,常用的有两种注解@Propert ...
- 在properties.xml中定义变量,在application.xml中取值问题
如果为application.xml中的变量赋默认值,同时又在properties.xml中变量赋值,而加载后是取不到properties.xml中的值的问题. 解决这个问题需要加上黑体部分配置: & ...
随机推荐
- 【Caffe】Ubuntu 安装 Caffe gpu版
安装环境:Ubuntu 16.04lts 64位, gcc5.4 gpu1050ti,cuda8.0,cudnn5.1.10 1. 安装依赖库 sudo apt-get install libprot ...
- 训练集、测试集loss容易出现的问题总结
train loss 不断下降,test loss不断下降:说明网络仍在学习; train loss 不断下降,test loss趋于不变:说明网络过拟合; train loss 趋于不变,test ...
- “Hello World”—— 第一个汇编程序
Hello World这是每一门编程语言的第一个最简单程序,下面那个程序就是汇编语言的Hello World.学汇编一段时间了,到现在才记录下自己的第一个汇编程序笔记.虽然这是个相当简单的小程序,但这 ...
- BZOJ1727:[Usaco2006 Open]The Milk Queue挤奶队列
我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html 题目传送门:https://www.lydsy.com/JudgeOnl ...
- Kill掉MySQL中所有sleep的client线程 (转)
vim killsleep.sh #It is used to kill processlist of mysql sleep #!/bin/sh while : do n=`mysqladmin ...
- Asp.net工作流workflow实战(一)
最近开发一个项目用到了工作流引擎,之前研究过微软的workflow所有就用它了,距离上次用有一段时间了,好多东西有点模糊了,就在此处一遍写代码一遍回忆. 首先,在我的项目中新建了.netframwor ...
- POJ2449:K短路
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 26355 Accepted: 7170 ...
- VisualGDB系列1:VisualGDB总体概述
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文总体介绍VisualGDB能给你带来 ...
- makefile基本语法
多文件编程的小例子功能:在main.c里面调用其他两个源文件里面的函数,然后输出字符串. 1.main.c #include"mytool1.h"#include" ...
- 具体问题:Spring 事务的隔离性,并说说每个隔离性的区别
使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/b ...