mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:35:50 +00:00
add current version displayed when mouse-over Help
This commit is contained in:
parent
c53309f640
commit
91be2b2c73
5 changed files with 177 additions and 90 deletions
7
pom.xml
7
pom.xml
|
@ -289,6 +289,13 @@
|
||||||
<version>${maven-war-plugin.version}</version>
|
<version>${maven-war-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<warName>petclinic</warName>
|
<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>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- gDickens: Include the Builders and Natures -->
|
<!-- gDickens: Include the Builders and Natures -->
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
src/main/webapp/META-INF/MANIFEST.MF
Normal file
10
src/main/webapp/META-INF/MANIFEST.MF
Normal 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
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
|
||||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
<%@ 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"/>
|
<spring:url value="/resources/images/banner-graphic.png" var="banner"/>
|
||||||
<img src="${banner}"/>
|
<img src="${banner}"/>
|
||||||
|
@ -16,8 +17,8 @@
|
||||||
<li style="width: 90px;"><a href="<spring:url value="/oups.html" htmlEscape="true" />"
|
<li style="width: 90px;"><a href="<spring:url value="/oups.html" htmlEscape="true" />"
|
||||||
title="trigger a RuntimeException to see how it is handled"><i
|
title="trigger a RuntimeException to see how it is handled"><i
|
||||||
class="icon-warning-sign"></i> Error</a></li>
|
class="icon-warning-sign"></i> Error</a></li>
|
||||||
<li style="width: 80px;"><a href="#" title="not available yet. Work in progress!!"><i
|
<li style="width: 80px;"><a href="#" title="not available yet. Work in progress!!
|
||||||
class=" icon-question-sign"></i> Help</a></li>
|
Spring Pet Clinic application v<%= VersionServlet.version %> "><i class=" icon-question-sign"></i> Help</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -86,4 +86,11 @@ see here: http://static.springsource.org/spring/docs/current/spring-framework-re
|
||||||
<servlet-name>petclinic</servlet-name>
|
<servlet-name>petclinic</servlet-name>
|
||||||
</filter-mapping>
|
</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>
|
</web-app>
|
Loading…
Reference in a new issue