Question

I'm just wondering, at what point does the Maven resource filtering mechanism inject values from a profile into a target file? I'm asking because my application is using Spring, and depending on a JVM property, it will call one of my apps environment files which is in turn used to supply configuration information to spring beans as they get created.

I would like to move passwords and db type info from the environment file into the Maven Settings.xml file however I'm wondering will Spring overwrite or conflict with the way Maven resource filtering is working?

The goal is for Spring to decide what environment the application is running in and choose an environment file which will have already had the necessary values injected by Maven.

Thanks

Was it helpful?

Solution

Maven replaces placeholders within the process-resources phase. See http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

So when spring starts creating its context the values are there.

You can use the PropertyPlaceholderConfigurer to read a properties file and make them available in the spring context:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>file://${config.dir}/external-config.properties</value>
        </list>
    </property>
</bean>

"config.dir" is in the system properties: java -Dconfig.dir=/dir/ or i think it can be a context parameter as well.

within the spring context ${key} from the properties file can be used to configure beans. Depending on the version of spring also annotations are available. Or there is a namespace for the PropertyResolver too.

So maven filtering and spring work nicely together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top