只需在src / main / resources中创建具有以下内容的文件app.properties
application.version=${project.version}然后像这样启用Maven过滤
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources>
就是这样-在应用程序代码中只需读取属性文件
ClassPathResource resource = new ClassPathResource( "app.properties" );p = new Properties();InputStream inputStream = null;try { inputStream = resource.getInputStream(); p.load( inputStream );} catch ( IOException e ) { LOGGER.error( e.getMessage(), e );} finally { Closeables.closeQuietly( inputStream );}并提供这样的方法
public static String projectVersion() { return p.getProperty( "application.version" );}


