Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display buildnumber in spring-based web application

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?

like image 670
Max Avatar asked Jul 07 '10 14:07

Max


1 Answers

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>
like image 142
axtavt Avatar answered Oct 09 '22 20:10

axtavt