property not found with multiple context:property-placeholder

前端 未结 4 967
温柔的废话
温柔的废话 2020-12-16 05:17

I am using spring 3.1 with spring profiles to load the beans. In my app context file, I load the properties like :



        
相关标签:
4条回答
  • 2020-12-16 05:40

    In my application I am using property-placeholder configurer in following way and it works very well. You can try that.

    <bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
              <property name="locations">
                <list>
                    <value>classpath*:META-INF/spring/*_${spring.profiles.active}.properties</value>
                </list>
              </property>
        </bean>
    

    I think this should resolve your problem. :)

    0 讨论(0)
  • 2020-12-16 05:45

    Since you have suggested hardcoding the path to the configuration file works, try using the profiles attribute on the tag to selectively include the configuration.

    <beans profile="profileName">
        <context:property-placeholder  order="1"  location="classpath*:META-INF/spring/hardcoded.properties" ignore-unresolvable="true"/>
    </beans>
    
    <beans profile="profileName2">    
        <context:property-placeholder order="1"  location="classpath*:META-INF/spring/hardcoded.properties" ignore-unresolvable="true"/>
    </beans>
    

    See this article explaining profiles: http://java.dzone.com/articles/using-spring-profiles-xml

    0 讨论(0)
  • 2020-12-16 05:49

    This bug about multiple property placeholders might relate to your problem: https://jira.spring.io/browse/SPR-9989

    When using multiple PropertyPlaceholderConfigurer in conjunction with @Value annotation and default value for placeholders syntax (ie ${key:defaultValue}), only the first PropertyPlaceholderConfigurer is used. If this configurer does not contain the desired value, it falls back to @Value default even if the second PropertyPlaceholderConfigurer contains the value.

    Affects Version/s: 3.1.3

    0 讨论(0)
  • 2020-12-16 05:54

    Each <context:property-placeholder> creates a new instance of PropertyPlaceholderConfigurer - it gets messy easily. You should have one such thing per application and on application level, not on libraries' one - that makes maintenance much easier.

    For more details and a suggestion how to cope with it look here: http://rostislav-matl.blogspot.cz/2013/06/resolving-properties-with-spring.html

    0 讨论(0)
提交回复
热议问题