Dagriel Dagriel - 1 year ago 142
Java Question

Configure Maven artifact version as Spring property

i'm trying to configure a property of a Spring bean to show the version of the Maven artifact. I need the property to be configured when the bean is loaded (not at runtime).


<bean id="myBean" class="com.domain.ClassName">
<property name="version" value="${???????}" />


private String version;

public String getVersion() {
return version;

public void setVersion(String version) {
this.version = version;

Is there a way to do this? More generally, is there a simple way to access properties from the POM xml on the Spring xml?

Thank you

Answer Source

You should have a look at the maven resource plugin. See : http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Basically the idea is that upon building your application, you will filter some of your project files to replace some text with what you want (in your case you want to place the version declared in your pom.xml into your spring.xml)

The key here is to understand that it is maven that, at build time, will do some replacement in your spring configuration file that will be used at runtime.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download