Using Maven <Resource> directive in conjunction with Spring PropertyPlaceholderConfigurer

Using Maven <Resource> directive in conjunction with Spring PropertyPlaceholderConfigurer allows maven variables to influence the run-time application property resolution.

Following from page Maven variables substitution in resource files during maven build, given that appbase is the specified directory from which maven build process will read resource files
and spit out the maven-variable substituted recreation of those resource files into

In the file

there is a property declaration
maxUsers = ${durian.maxUsers}
There is a corresponding property definition in the pom.xml
After maven build, the deployed property file will be
The property declaration has resolved to be
maxUsers = 8

PropertyPlaceholderConfigurer declared in Spring config registers the application properties from the specified property files to allow them to be accessed during run-time.
  <property name="location">
The property named location specifies the location of the property file, whose property definitions are to be exposed to Spring context. To expose properties from multiple property files, the property named locations is used:
  <property name="locations">

    location="classpath:properties/" ignore-unresolvable=”true”/>
Having a property-placeholder declaration per property file, which will be resolved n the order they are declared. All property-placeholder declarations, except the last one, should have the attribute ignore-unresolvable=”true”, to allow distributing properties over more than one locations without encountering unresolvable property error..

No comments:

Post a Comment