PropertyPlaceHolderConfigurer中的location是不是用错了?
本文由作者张远道授权网易云社区发布。
spring中常用PropertyPlaceHolderConfigurer来读取properties配置文件的配置信息。常用的配置方式有两种,一种是使用location
<bean id="property" >
<property="location" value="classpath:myproperty.propeties"/>
</bean>
另一种是使用locations
<bean id="property"
<property="locations">
<list>
<value>classpath:myproperty.propeties</value>
<value>classpath:myproperty1.properties</value>
</list>
</property>
</bean>
查看PropertyPlaceHolderConfigurer的源码发现,整个PropertyPlaceHolderConfigurer的继承树中都没有location整个属性,仅仅只有locations这个属性。如下图所示。
因此,认为既然没有location这个属性,那使用时是不是不正确。但是仔细看看发现了PropertiesLoaderSupport中有setLocation()方法。
而查看spring有关依赖注入的源码:
即获得property对应的setter方法,以及property对应的值,然后通过反射,调用该方法即可。可以看出,不要求类的定义中真正包含改属性,只要对应的setter方法被调用即可以。因此,ioc容器从xml配置中读到属性为location的值,然后获得location对应的setter方法,即setLocation,然后通过反射,将location的值传入了setLocation中。如下图。
结论:location属性没有使用错,而是spring根据反射调用setLocation方法,将location赋值给了locations了而已。
免费领取验证码、内容安全、短信发送、直播点播体验包及云服务器等套餐
更多网易技术、产品、运营经验分享请访问网易云社区。
相关文章:
【推荐】 适配的那些事
PropertyPlaceHolderConfigurer中的location是不是用错了?的更多相关文章
- javascript 中的location.href 并不是立即执行的,是在所在function 执行完之后执行的。
javascript 中的location.href 并不是立即执行的,是在所在function 执行完之后执行的. 1 function getUrl(tp) { if (tp == 'd') { ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
关于js中"window.location.href"."location.href"."parent.location.href".&qu ...
- nginx配置文件中的location理解
关于一些对location认识的误区 1. location 的匹配顺序是"先匹配正则,再匹配普通". 矫正: location 的匹配顺序其实是"先匹配普通,再匹配正则 ...
- angularjs 中通过 $location 进行路由跳转传参
$location.path('/page1').search({id: $scope.id,name:$scope.name}); 带参数跳转页面,在新的页面通过$routeParams接收参数 $ ...
- Angular中通过$location获取地址栏的参数详解
Angular中通过$location获取url中的参数 最近,项目开发正在进行时,心有点燥,许多东西没来得及去研究,今天正想问题呢,同事问到如何获取url中的参数,我一时半会还真没想起来,刚刚特意研 ...
- [转] Nginx配置中的location、root、alias
Nginx配置中的location.root.alias location & root 初始配置 [root@adailinux vhost]# cat rio.conf server { ...
- javascript中的location的用法
javascript中的location.href有很多种用法,主要如下. self.location.href="/url" 当前页面打开URL页面 location.href= ...
- Nginx中的 location 匹配和 rewrite 重写跳转
Nginx中的location匹配和rewrite重写跳转 1.常用的Nginx正则表达式 2.location 3.rewrite 4.rewrite实例 1.常用的Nginx正则表达式: ^ :匹 ...
- Nginx中的Location和Rewrite
Nginx中的Location和Rewrite 目录 Nginx中的Location和Rewrite 一.location 1. location的分类 2. location常用的匹配规则 3. l ...
随机推荐
- swift 移除所有子控件
/// 移除所有子控件 func removeAllSubViews(){ if self.view.subviews.count>0{ self.view.subviews.forEach({ ...
- struts框架值栈问题七之EL表达式也会获取到值栈中的数据
7. 问题七:为什么EL也能访问值栈中的数据? * StrutsPreparedAndExecuteFilter的doFilter代码中 request = prepare.wrapRequest(r ...
- db2 查看表空间使用率
1. 统计所有节点表空间使用率 select substr(TABLESPACE_NAME,1,20) as TBSPC_NAME,bigint(TOTAL_PAGES * PAGE_SIZE)/10 ...
- chrome 调试工具的使用
Elements chrome devtools 中 Elements panel 是审查 dom 元素和 css 的, 可以实时修改 dom/css. windows: ctrl + shift + ...
- 查询yum包安装路径
rpm -ql php71-php yum install json yum install libcurl
- pip安装包
默认的在安装文件的Lib\site-packages\路径下面 cmd窗口 cd切换路径:C:\Users\admin\AppData\Local\Programs\Python\Python36\S ...
- oracle 新建数据库 ,新建用户
net manager 数据库名----电脑名localhost 1521 , 服务名 orcl (oracle 版本不一样, 不同版本不一样,,) 然后测试.. sys 账号登录 新建用 ...
- Nginx的使用(反向代理,负载均衡)
在我目前的工作内容中,接触到Nginx的用处无外乎两点: 1. 反向代理,解决前端跨域的问题 工作内容有门户的概念,就是将各个子系统集成到门户里,在门户里面访问,这样就很容易造成跨域的问题 那么解决的 ...
- 十年前,女:“对不起,我不会喜欢你的,你不要再坚持了,就好比让 Linux 和 Windows 同时运行在一台PC机上,可能吗?
1.十年前,女:“对不起,我不会喜欢你的,你不要再坚持了,就好比让 Linux 和 Windows 同时运行在一台PC机上,可能吗?”男生听后默默走开, 十年后,在一次虚拟技术大会上,我听到一名虚拟技 ...
- 2018.07.23 洛谷P4513 小白逛公园(线段树)
传送门 线段树常规操作了解一下. 单点修改维护区间最大连续和. 对于一个区间,维护区间从左端点开始的连续最大和,从右端点开始的连续最大和,整个区间最大和,区间和. 代码如下: #include< ...