How to use property-placeholder for file on filesystem

前端 未结 2 588
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 23:03

We used to have a way to load properties from a file on the classpath:



        
相关标签:
2条回答
  • 2021-01-03 23:53

    This did work for me:

    <context:property-placeholder location="file:/path/to/myConfigFile.properties" />
    

    But this (interestingly) did not:

    <context:property-placeholder location="#{ systemProperties['foo'] }" />
    

    I got

    java.io.FileNotFoundException: Could not open ServletContext resource [/#{ systemProperties['foo'] }]
    

    You're not going to be able to use a property placeholder ${..} with the definition of a PropertyPlaceholderConfigurer. It's the chicken before the egg.

    You can always subclass PropertyPlaceholderConfigurer and have it do whatever you want (for example, call setLocations() in a @PostConstruct method. Then, instead of using <context:property-placeholder>, use:

    <bean class="com.foo.MyPropertyPlaceholderConfigurer"/>
    
    0 讨论(0)
  • 2021-01-04 00:02

    What about this way?

    <context:property-placeholder properties-ref="prop" />
    
    <util:properties id="prop" location="reso"/>
    
    <bean id="reso" class="org.springframework.core.io.FileSystemResource">
        <constructor-arg index="0" value="/yourpathandfile" />
    </bean>
    
    0 讨论(0)
提交回复
热议问题