如何在基于Spring的Web应用程序中显示内部版本号 [英] How to display buildnumber in spring-based web application

查看:290
本文介绍了如何在基于Spring的Web应用程序中显示内部版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在index.jsp页面上显示内部版本号

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Title (build: BUILDNUMBER )
</head>

内部版本号可以由maven提供到* .properties文件中. 用Spring读取* .properties文件并显示属性的最佳方法是什么?

解决方案

您可以将.properties文件作为本地化消息源加载(使用

JSP文件:

Version: <spring:message code = "buildNumber" />

pom.xml:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

I need to display build number in my index.jsp page

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Title (build: BUILDNUMBER )
</head>

The build number can be supplied by maven into a *.properties file. What is the best way to read *.properties file and display a property with Spring?

You may load the .properties file as a localization message source (using ResourceBundlerMessageSource) and access it in JSP using <spring:message> or <fmt:message>:

src/main/resources/buildInfo.properties:

buildNumber=${buildNumber}

where buildNumber is exposed as Roland Schneider suggests.

Context configuration:

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name = "basenames"><value>buildInfo</value></property>
    <!-- Or a comma separated list if you have multiple .properties files -->
</bean>

JSP file:

Version: <spring:message code = "buildNumber" />

pom.xml:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

这篇关于如何在基于Spring的Web应用程序中显示内部版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆