add current version displayed when mouse-over Help

This commit is contained in:
伟保罗 Paul Verest 2013-03-18 11:41:28 +08:00
parent c53309f640
commit 91be2b2c73
5 changed files with 177 additions and 90 deletions

View file

@ -289,6 +289,13 @@
<version>${maven-war-plugin.version}</version>
<configuration>
<warName>petclinic</warName>
<!-- http://stackoverflow.com/questions/2712970/how-to-get-maven-artifact-version-at-runtime -->
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<!-- gDickens: Include the Builders and Natures -->

View file

@ -0,0 +1,62 @@
package org.springframework.samples.petclinic.web;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* http://stackoverflow.com/questions/14934299/how-to-get-package-version-at-running-tomcat
* http://stackoverflow.com/questions/2712970/how-to-get-maven-artifact-version-at-runtime
* http://stackoverflow.com/questions/809775/what-does-the-servlet-load-on-startup-value-of-0-zero-signify
*
* Example of MANIFEST.MF from META-INF/
<pre>
Manifest-Version: 1.0
Implementation-Vendor: Funshion
Implementation-Title: atlas-app
Implementation-Version: 1.1.5.M2.0-SNAPSHOT
Implementation-Vendor-Id: com.funshion.microlens
Built-By: weibl
Build-Jdk: 1.6.0_37
Specification-Vendor: Funshion
Specification-Title: atlas-app
Created-By: Apache Maven 3.0.4
Specification-Version: 1.1.5.M2.0-SNAPSHOT
Archiver-Version: Plexus Archiver
<pre/>
* @author Paul Verest
* Reviewer
* @since 2013-3-18
*/
public class VersionServlet extends HttpServlet {
private static final long serialVersionUID = -2805284042253311925L;
protected static final Logger logger = LoggerFactory.getLogger(VersionServlet.class);
public static String version = "UNDEFINED";
@Override
public void init() throws ServletException {
version = getClass().getPackage().getImplementationVersion();
if (version==null) {
Properties prop = new Properties();
try {
prop.load(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
version = prop.getProperty("Implementation-Version");
} catch (IOException e) {
logger.error(e.toString());
}
}
logger.info("Starting Spring Pet Clinic application version "+version);
}
@Override
public void destroy() {
logger.info("Stopping Spring Pet Clinic application version "+version);
}
}

View file

@ -0,0 +1,10 @@
Manifest-Version: 1.0
Implementation-Title: petclinic
Implementation-Version: 1.0.0-SNAPSHOT
Implementation-Vendor-Id: org.springframework.samples
Build-Jdk: 1.6.0_37
Built-By: weibl
Specification-Title: petclinic
Created-By: Apache Maven 3.0.4
Specification-Version: 1.0.0-SNAPSHOT

View file

@ -1,5 +1,6 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page import="org.springframework.samples.petclinic.web.VersionServlet"%>
<spring:url value="/resources/images/banner-graphic.png" var="banner"/>
<img src="${banner}"/>
@ -16,8 +17,8 @@
<li style="width: 90px;"><a href="<spring:url value="/oups.html" htmlEscape="true" />"
title="trigger a RuntimeException to see how it is handled"><i
class="icon-warning-sign"></i> Error</a></li>
<li style="width: 80px;"><a href="#" title="not available yet. Work in progress!!"><i
class=" icon-question-sign"></i> Help</a></li>
<li style="width: 80px;"><a href="#" title="not available yet. Work in progress!!
Spring Pet Clinic application v<%= VersionServlet.version %> "><i class=" icon-question-sign"></i> Help</a></li>
</ul>
</div>
</div>

View file

@ -86,4 +86,11 @@ see here: http://static.springsource.org/spring/docs/current/spring-framework-re
<servlet-name>petclinic</servlet-name>
</filter-mapping>
<!-- The first servlet to get loaded to know app version -->
<servlet>
<servlet-name>versionServlet</servlet-name>
<servlet-class>org.springframework.samples.petclinic.web.VersionServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
</web-app>