Java – references the spring properties file using a path relative to the configuration file
I am moving properties from my spring configuration file to a separate properties file This is included in the configuration file
<bean class="org.springframework.beans.factory.config.PropertyPlaceHolderConfigurer"> <property name="location" value="file:properties/${CONfig_MODE}/service.properties" /> </bean>
In this regard, the location of the properties file is relative to the current working directory of the server process
This will create a requirement that the process must be started from a specific working directory, and even worse, allowing (which can be remote) may select a completely different property file, for example, if the working directory is set to an older version of the service
I want to reference the properties file using a path relative to the directory containing the configuration file
Looking at the file system resource, it seems that createrelative may be what I need, but I can't figure out how to use it in the configuration file
thank you,
Steve
Solution
I don't know how to do that
However, what you can do is load the properties file from the classpath:
<bean class="org.springframework.beans.factory.config.PropertyPlaceHolderConfigurer"> <property name="location" value="classpath:path/to/service.properties" /> </bean>
The classpath location of the properties file is a more predictable situation. As long as your classpath is set correctly, it will work