1.问题

dubbo client配置:

	<dubbo:reference id="channelCustomerClient" interface="com.gttown.crm.channel.service.ChannelCustomerService"
timeout="60000" check="false" filter="clientFilter" retries="0" validation="false"
url="${dubbo.url.channel:#{null}}"/>

dubbo.properties:

		zipkin.url=http://zipkin.dev.great-tao.com
dubbo.application=gttown-user-web
dubbo.register=false
dubbo.port=20880
dubbo.url.channel=dubbo://127.0.0.1:20881

dubbo配置时,预期效果:url="${dubbo.url.channel:#{null}}" 会先读取配置文件dubbo.url.channel的值如果有值则读取,若配置文件无该值则用默认值null。

但是事实上无论dubbo.properties配置文件是否有dubbo.url.channel。url的值都会强制使用默认值null。

PropertyPlaceholderConfigurer配置参考。 (具体参考http://elim.iteye.com/blog/2387138)

2.原因

spring.xml 里的PropertyPlaceholderConfigurer配置:

	<bean id="placeholderConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:/*.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

db-user.xml 里的PropertyPlaceholderConfigurer配置:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="-1"/>
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

spring.xml的PlaceholderConfigurer配置扫描了classpath下的全部文件,但是加载顺序order使用的是默认值。

db-user.xml的PlaceholderConfigurer配置只扫描了classpath下的db.properties,加载顺序order为-1最后加载。

url="${dubbo.url.channel:#{null}}"配置时由于db-user.xml的PlaceholderConfigurer后加载,而该PlaceholderConfigurer只扫描了db.properties。该文件没有dubbo.url.channel的值,导致url使用默认值null。

3.解决

  • 方案1:

    spring.xml 里的PropertyPlaceholderConfigurer配置加上

          <property name="order" value="-1"/>

建议:扫面范围越大的PropertyPlaceholderConfigurer越后面加载。

  • 方案2:

    删除db-user.xml 以及以其他配置文件里的精确扫描指定文件的PropertyPlaceholderConfigurer配置。

  • 方案3:

    spring.xml 里的PropertyPlaceholderConfigurer配置,修改分隔符(默认分隔符为:)

      <property name="valueSeparator" value="&"/>

使用& 作为分隔符。

dubbo-clien.xml配置修改为

url="${dubbo.url.channel&#{null}}

Spring的PropertyPlaceholderConfigurer强制使用默认值的坑的更多相关文章

  1. spring mvc 绑定参数据默认值,是否必传,(RequestParam(value="id",defaultValue="1",required=true) )

    @RequestMapping(value = "/detail", method = RequestMethod.GET) public String newDetail(@Re ...

  2. 【oracle】关于创建表时用default指定默认值的坑

    刚开始学create table的时候没注意,学到后面发现可以指定默认值.于是写了如下语句: 当我查询的时候发现,查出来的结果是这样的.. 很纳闷有没有,我明明指定默认值了呀,为什么创建出来的表还是空 ...

  3. 关于spring的注解方式注入默认值(转) -- 首字母小写

    1.是首字母小写 比如 UserAction对应的id是userAction 可以通过ApplicationContext 对象的act.getBean("userAction") ...

  4. spring 配置文件属性设置默认值以及读取环境变量值

    在 Spring 中为 javabean 注入属性文件中的属性值一般人都知道的,可以通过 org.springframework.beans.factory.config.PropertyPlaceh ...

  5. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-002-激活PROFILE、设置默认值、@ActiveProfiles

    一. Spring honors two separate properties when determining which profiles are active:spring.profiles. ...

  6. spring @Value 设置默认值

    @Value("${spring.value.test}") private String value; 如果配置文件中没有设置 spring.value.test 在启动的时候讲 ...

  7. 给Spring的placeholder设置默认值

    问题:使用Spring时,可以方便地通过placeholder的形式${key}将key对应的properities定义value,注入到Bean中.但是如果在properities文件中,没有对ke ...

  8. spring中使用@Value设置全局变量默认值

    前几天在开发过程中遇到一个使用 spring 的 @Value 给类的全局变量设置默认值不成功的问题,最后通过查资料也是轻松解决,但是发现使用@Value也是有多种多样的方式,今天总算是将开发任务结束 ...

  9. Spring boot Jpa添加对象字段使用数据库默认值

    Spring boot Jpa添加对象字段使用数据库默认值 jpa做持久层框架,项目中数据库字段有默认值和非空约束,这样在保存对象是必须保存一个完整的对象,但在开发中我们往往只是先保存部分特殊的字段其 ...

随机推荐

  1. 多进程Multiprocessing模块

    多进程 Multiprocessing 模块 先看看下面的几个方法: star() 方法启动进程, join() 方法实现进程间的同步,等待所有进程退出. close() 用来阻止多余的进程涌入进程池 ...

  2. Sublime text使用快捷键

    作者:gyfnice链接:https://www.zhihu.com/question/24896283/answer/34327939来源:知乎著作权归作者所有,转载请联系作者获得授权. 代码片段 ...

  3. Java之增强的for 循环

    3. 增强for循环 1) 作用: 对存储对象的容器进行迭代 2)  jdk5以前怎么迭代 3) 增强for循环迭代数组 String [] arr = {"a", "b ...

  4. js算法初窥04(算法模式01-递归)

    终于来到了有点意思的地方--递归,在我最开始学习js的时候,基础课程的内容就包括递归,但是当时并不知道递归的真正意义和用处.我只是知道,哦...递归是自身调用自身,递归要记得有一个停止调用的条件.那时 ...

  5. 读取txt内文件内容

    命令如下: f = open("c:\\1.txt","r")  lines = f.readlines()#读取全部内容  for line in lines ...

  6. APP界面设计与页面布局的23条基本原则

    一个App的好与不好,很大部分取决于移动App页面布局的合理性,优秀的布局顾名思义就是对页面的文字.图形或表格等进行排版.设计. 优秀的布局,需要对页面信息进行完整的考虑,既要考虑用户需求.用户行为, ...

  7. 常用 Linux 命令的基本使用

    常用 Linux 命令的基本使用 操作系统 作用:管理好硬件设备,让软件可以和硬件发生交互类型 桌面操作系统 Windows macos linux 服务器操作系统 linux Windows ser ...

  8. 了解Scala反射

    本篇文章主要让大家理解什么是Scala的反射, 以及反射的分类, 反射的一些术语概念和一些简单的反射例子. 什么是反射 我们知道, Scala是基于JVM的语言, Scala编译器会将Scala代码编 ...

  9. hive删除表和表中的数据

    hive删除表和表中的数据,以及按分区删除数据 hive删除表: drop table table_name; hive删除表中数据: truncate table table_name; hive按 ...

  10. 基于Unity的AR开发初探:第一个AR应用程序

    记得2014年曾经写过一个Unity3D的游戏开发初探系列,收获了很多好评和鼓励,不过自那之后再也没有用过Unity,因为没有相关的需求让我能用到.目前公司有一个App开发的需求,想要融合一下AR到A ...