美文网首页
spring中 context:property-placeho

spring中 context:property-placeho

作者: Jermy_7a2a | 来源:发表于2018-07-06 10:26 被阅读0次

Spring容器采用反射扫描的发现机制,在探测到Spring容器中有一个 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的 Bean就会停止对剩余PropertyPlaceholderConfigurer的扫描(Spring 3.1已经使用PropertySourcesPlaceholderConfigurer替代 PropertyPlaceholderConfigurer了)。

换句话说,即Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或),其余的会被Spring忽略掉。

拿上来的例子来说,如果A和B模块是单独运行的,由于Spring容器都只有一个PropertyPlaceholderConfigurer, 因此属性文件会被正常加载并替换掉。如果A和B两模块集成后运行,Spring容器中就有两个 PropertyPlaceholderConfigurer Bean了,这时就看谁先谁后了, 先的保留,后的忽略!因此,只加载到了一个属性文件,因而造成无法正确进行属性替换的问题。

使用spring提供的通配符就OK了

<context:property-placeholder location="classpath*:*.properties"/>

相关文章

网友评论

      本文标题:spring中 context:property-placeho

      本文链接:https://www.haomeiwen.com/subject/grhuwttx.html