views:

60

answers:

2

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?

+1  A: 
Roland Schneider
It's possible to filter *web resources* but not like this, a JSP is not a *resource*.
Pascal Thivent
What's the right way then?
artemb
@artemb: Open a question?
Pascal Thivent
+3  A: 

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>
axtavt
The bird have flew after i've added liteners to web.xml: <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>
Max