spring - 如何在基于 Spring 的 Web 应用程序中显示内部版本号

标签 spring jsp maven-2 build-process

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

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

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

最佳答案

您可以加载 .properties文件作为本地化消息源(使用 ResourceBundlerMessageSource )并在 JSP 中使用 <spring:message> 访问它或 <fmt:message> :

src/main/resources/buildInfo.properties :

buildNumber=${buildNumber}

在哪里 buildNumber正如 Roland Schneider 所建议的那样暴露出来。

上下文配置:

<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 文件:

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

pom.xml :

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

关于spring - 如何在基于 Spring 的 Web 应用程序中显示内部版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3195871/

相关文章:

java - Maven 2 & 打包 ejb 与 jar

java - 如何使用Apache Kafka实现 "Exactly once"kafka消费者?

java - 基于 Spring 注解的表单验证

java - 业务层使用@Context注解访问HttpServletRequest

java - 对于总是很慢的服务,REST API 请求超时

javax.el.PropertyNotFoundException : No public static field named [ShoppingBag] was found on class [Others. 客户]

jsp - 将自定义对象从 servlet 传递到 JSP

java - URL 请求参数 JSP 错误

java - Cobertura 拒绝承认代码已被覆盖

eclipse - 如何在 Eclipse 中保存时启动 Maven "compile"目标?