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

@ -1,89 +1,96 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Spring PetClinic</display-name>
<description>Spring PetClinic sample application</description>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>jdbc</param-value>
<!-- Available profiles:
<param-value>jdbc</param-value>
<param-value>jpa</param-value> (in the case of plain JPA)
<param-value>spring-data-jpa</param-value> (in the case of Spring Data JPA)
-->
</context-param>
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderServlet.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-config.xml, classpath:spring/tools-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
<servlet-name>petclinic</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/mvc-core-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>petclinic</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Dandelion-Datatables servlet definition -->
<servlet>
<servlet-name>datatablesController</servlet-name>
<servlet-class>com.github.dandelion.datatables.extras.servlet2.servlet.DatatablesServlet</servlet-class>
</servlet>
<!-- Dandelion-Datatables servlet mapping -->
<servlet-mapping>
<servlet-name>datatablesController</servlet-name>
<url-pattern>/datatablesController/*</url-pattern>
</servlet-mapping>
<!-- Dandelion-Datatables filter definition -->
<filter>
<filter-name>datatablesFilter</filter-name>
<filter-class>com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter</filter-class>
</filter>
<!-- Dandelion-Datatables filter mapping -->
<filter-mapping>
<filter-name>datatablesFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- used so we can use forms of method type 'PUT' and 'DELETE'
see here: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/view.html#rest-method-conversion
-->
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<servlet-name>petclinic</servlet-name>
</filter-mapping>
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Spring PetClinic</display-name>
<description>Spring PetClinic sample application</description>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>jdbc</param-value>
<!-- Available profiles:
<param-value>jdbc</param-value>
<param-value>jpa</param-value> (in the case of plain JPA)
<param-value>spring-data-jpa</param-value> (in the case of Spring Data JPA)
-->
</context-param>
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderServlet.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-config.xml, classpath:spring/tools-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
<servlet-name>petclinic</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/mvc-core-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>petclinic</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Dandelion-Datatables servlet definition -->
<servlet>
<servlet-name>datatablesController</servlet-name>
<servlet-class>com.github.dandelion.datatables.extras.servlet2.servlet.DatatablesServlet</servlet-class>
</servlet>
<!-- Dandelion-Datatables servlet mapping -->
<servlet-mapping>
<servlet-name>datatablesController</servlet-name>
<url-pattern>/datatablesController/*</url-pattern>
</servlet-mapping>
<!-- Dandelion-Datatables filter definition -->
<filter>
<filter-name>datatablesFilter</filter-name>
<filter-class>com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter</filter-class>
</filter>
<!-- Dandelion-Datatables filter mapping -->
<filter-mapping>
<filter-name>datatablesFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- used so we can use forms of method type 'PUT' and 'DELETE'
see here: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/view.html#rest-method-conversion
-->
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<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>