propertiesfactorybean vs propertyplaceholderconfigurer spring?

来源:互联网 发布:淘宝网页版回收站 编辑:程序博客网 时间:2024/06/07 11:34

PropertiesFactoryBean is a FactoryBean implementation which reads a properties file and exposes that as an Properties object in the applicationcontext. 
加载配置文件后,可以在代码中通过注解直接使用,如

<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">    <span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@Value</span>(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">#{qfangCoreSameProperties[<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'joinLoginSuccessUrl'</span>]}</span>"</span>)    private <span class="hljs-constant" style="box-sizing: border-box;">String</span> joinLoginSuccessUrl;</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

PropertyPlaceHolderConfigurer is a BeanFactoryPostProcessor implementation that reads a property file and uses that property file to replace placeholder variables (${somename}) with actual values. The read properties aren’t available as a Properties object. 
在配置文件中使用,如

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">    <dubbo:registry address=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">${dubbo.registry.address}</span>"</span> />    <dubbo:monitor protocol=<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">${dubbo.monitor.protocol}</span>"</span> /></code>
0 0
原创粉丝点击