zoukankan      html  css  js  c++  java
  • spring 之 property-placeholder 分析2

    其实我们可以完全不使用  context:property-placeholder  ,而是使用 PropertySourcesPlaceholderConfigurer :

        <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
            <property name="location">
                    <value>app.properties</value>
            </property>
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
        </bean>

    注意,其中的locations 不能这么写:

    <property name="location">
          <list>
             <value>classpath:foo.properties</value>
          </list>
       </property>

    需要把其中的list 去掉, 也没有深究为什么。 大概是spring 版本问题吧

    根据前面的分析,我们知道,其实property-placeholder就是用到了 PropertySourcesPlaceholderConfigurer。

        <context:property-placeholder location="appa.properties,app.properties"/>

    对比可知, 其实property-placeholder 简单了很多, 其实property-placeholder  就是一个简化写法。

    两者是可以共存的, 每个都会对 所有的 bean 定义全部的循环 尝试做替换处理。所以最好不要同时写两个, 这样会效率比较低, 而是把 多个properties文件配置在其中一个 地方, 用逗号分开。

    参考:

    https://dzone.com/articles/properties-spring 

  • 相关阅读:
    LINUX-redis & mongodb
    Linux -Docker
    Python 爬虫 58同城
    Python 爬虫 当当网图书 scrapy
    Python 爬虫 NewCnblogs (爬虫-Django-数据分析)
    Python 通用爬虫 和讯博客 scrapy
    selenium
    MongoDB
    Python-Django-Djangorestframwork
    Python-WEB -VUE初识 + webstorm
  • 原文地址:https://www.cnblogs.com/FlyAway2013/p/7826633.html
Copyright © 2011-2022 走看看