简体   繁体   中英

How I can configure properties file right?

I have maven project with several modules

this is part of database-config.xml in office-core module:

<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
             <list>
                   <value>classpath:application.properties</value>
             </list>
      </property>
</bean>

I have application.properties files on several places:

c:\\projects\\office\\app\\office-core\\application.properties

c:\\projects\\office\\app\\office-core\\src\\main\\profiles\\application.properties

c:\\projects\\office\\app\\application.properties

In my opinion with this config in database-config.xml I should can use the properties file in my database-config.xml but I cant... Any help ?

You should put the application.properties file to src/main/resources directory to have it effectively on classpath. Then it should work.

I think it will not work because those paths are not part of your classpath. I suggest you to have some default configuration and to have configuration override per module, something like that:

<bean id="overrideConfigurer" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
    <property name="location" value="file:/SomeFolderInFileSystem/conf.properties"/>
    <property name="ignoreResourceNotFound" value="true"/>
</bean>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM