在Spring配置文件中访问maven项目版本 [英] Access maven project version in Spring config files
问题描述
我想在页面中显示我当前运行的Web应用程序版本。该项目基于Maven,Spring和Wicket。
I would like to display the currently running version of my web application in the page. The project is based on Maven, Spring, and Wicket.
我想以某种方式获得maven的价值 $ {project.version}
并在我的spring XML文件中使用它,类似于我使用Spring PropertyPlaceholderConfigurer读取属性文件以获取我在我的应用程序中使用的设置的方式。
I'd like to somehow get the value of maven's ${project.version}
and use it in my spring XML files, similarly to the way I use the Spring PropertyPlaceholderConfigurer to read a property file for settings that I use in my application.
如果我在我的Spring配置中将maven project.version
作为变量提供,我可以做类似的事情这个:
If I had the maven project.version
available as a variable in my Spring config, I could do something like this:
<bean id="applicationBean" class="com.mysite.web.WicketApplication">
<property name="version"><value>${project.version}</value></property>
</bean>
我该怎么做?
推荐答案
您可以使用Maven 过滤已经建议。
You can use Maven filtering as already suggested.
或者您可以直接使用Spring读取Maven在META-INF目录下创建的 pom.properties
文件:
Or you could just read the pom.properties
file created by Maven under META-INF directory directly with Spring:
<util:properties id="pom"
location="classpath:META-INF/groupId/artifactId/pom.properties" />
并使用bean。
后一种方法的唯一缺点是 pom.properties
是在创建的包
阶段时间(并且在 test
期间不会出现)。
The only drawback of the later approach is that the pom.properties
is created at package
phase time (and won't be there during, say, test
).
这篇关于在Spring配置文件中访问maven项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!