diff --git a/pom.xml b/pom.xml index 5bb290527..2f890a4fc 100644 --- a/pom.xml +++ b/pom.xml @@ -289,6 +289,13 @@ ${maven-war-plugin.version} petclinic + + + + true + true + + diff --git a/src/main/java/org/springframework/samples/petclinic/web/VersionServlet.java b/src/main/java/org/springframework/samples/petclinic/web/VersionServlet.java new file mode 100644 index 000000000..e2cbf4e92 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/web/VersionServlet.java @@ -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/ +
+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
+
+ * @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);
+	}
+
+}
diff --git a/src/main/webapp/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..213bbb427
--- /dev/null
+++ b/src/main/webapp/META-INF/MANIFEST.MF
@@ -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
+
diff --git a/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp b/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp
index 76c184417..930c63ec6 100644
--- a/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp
+++ b/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp
@@ -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"%>
 
 
 
@@ -16,8 +17,8 @@
             
  • " title="trigger a RuntimeException to see how it is handled"> Error
  • -
  • Help
  • +
  • Help
  • diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 92fe20425..eae8b7236 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,89 +1,96 @@ - - - - Spring PetClinic - Spring PetClinic sample application - - - spring.profiles.active - jdbc - - - - - - contextConfigLocation - classpath:spring/business-config.xml, classpath:spring/tools-config.xml - - - - org.springframework.web.context.ContextLoaderListener - - - - - petclinic - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - classpath:spring/mvc-core-config.xml - - 1 - - - - petclinic - / - - - - - datatablesController - com.github.dandelion.datatables.extras.servlet2.servlet.DatatablesServlet - - - - - datatablesController - /datatablesController/* - - - - - datatablesFilter - com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter - - - - - datatablesFilter - /* - - - - - httpMethodFilter - org.springframework.web.filter.HiddenHttpMethodFilter - - - - httpMethodFilter - petclinic - - + + + + Spring PetClinic + Spring PetClinic sample application + + + spring.profiles.active + jdbc + + + + + + contextConfigLocation + classpath:spring/business-config.xml, classpath:spring/tools-config.xml + + + + org.springframework.web.context.ContextLoaderListener + + + + + petclinic + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath:spring/mvc-core-config.xml + + 1 + + + + petclinic + / + + + + + datatablesController + com.github.dandelion.datatables.extras.servlet2.servlet.DatatablesServlet + + + + + datatablesController + /datatablesController/* + + + + + datatablesFilter + com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter + + + + + datatablesFilter + /* + + + + + httpMethodFilter + org.springframework.web.filter.HiddenHttpMethodFilter + + + + httpMethodFilter + petclinic + + + + + versionServlet + org.springframework.samples.petclinic.web.VersionServlet + 0 + + \ No newline at end of file