I'm displaying some version metadata in my web application, and I do this using a Maven resources filter that will update one of my properties files.
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>build-info.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>build-info.properties</exclude>
</excludes>
</resource>
</resources>
My properties file
build.version = ${project.version}
build.number = ${BUILD_NUMBER}
build.commit = ${git.commit.id.abbrev}
This all works great, the appropriate information gets added to the resource when I package the application.
My problem is that I tried to use a Spring PropertyPlaceholderConfigurer to wire together a bean containing the version information, but this doesn't like the ${}
syntax. I can no longer run the application locally without an ugly workaround. I'm getting the following exception:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'com.mycompany.abc.dm.system.BuildInfo
...
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'project.version' in string value "${project.version}"
Is there anyway around this using the PropertyPlaceholderConfigurer?
Here is the snippet from the Spring XML context
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:build-info.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1000" />
</bean>
<bean class="com.mycompany.abc.dm.system.BuildInfo">
<constructor-arg index="0" value="${build.version}"/>
<constructor-arg index="1" value="${build.number}"/>
<constructor-arg index="2" value="${build.commit}"/>
</bean>
"Solution"
I never found a way around this issue using the PropertyPlaceholderConfigurer. My solution was to not use PropertyPlaceholderConfigurer. I'm still reading the properties file, just not with Spring magic.