This commit is contained in:
Mark Thomas 2016-05-20 08:39:23 +00:00
commit 8733f9dff5
4 changed files with 167 additions and 119 deletions

View file

@ -163,7 +163,6 @@
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency> </dependency>
<!-- Date and Time --> <!-- Date and Time -->

View file

@ -0,0 +1,43 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.samples.petclinic.util;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
/**
* When the web application stops, various resources need to be cleaned up to
* prevent memory leaks.
*/
public class CleanUp implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent arg0) {
// NO-OP
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// Logback is configured to use JMX so make sure that all objects are
// deregistered from JMX else there will be a memory leak
// http://logback.qos.ch/manual/jmxConfig.html
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.stop();
}
}

View file

@ -8,7 +8,10 @@
</contextListener> </contextListener>
<!-- To enable JMX Management --> <!-- To enable JMX Management -->
<jmxConfigurator/> <jmxConfigurator/>
<!-- Avoid conflicts with other web applications using logback and JMX -->
<contextName>PetClinic</contextName>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder> <encoder>

View file

@ -1,118 +1,121 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="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_3_0.xsd" http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true"> version="3.0" metadata-complete="true">
<display-name>Spring PetClinic</display-name> <display-name>Spring PetClinic</display-name>
<description>Spring PetClinic sample application</description> <description>Spring PetClinic sample application</description>
<!-- When using Spring jpa, use the following: --> <!-- When using Spring jpa, use the following: -->
<context-param> <context-param>
<param-name>spring.profiles.active</param-name> <param-name>spring.profiles.active</param-name>
<param-value>jpa</param-value> <param-value>jpa</param-value>
</context-param> </context-param>
<!-- When using Spring JDBC, use the following: --> <!-- When using Spring JDBC, use the following: -->
<!-- <context-param> <!-- <context-param>
<param-name>spring.profiles.active</param-name> <param-name>spring.profiles.active</param-name>
<param-value>jdbc</param-value> <param-value>jdbc</param-value>
</context-param> --> </context-param> -->
<!-- the CallMonitoringAspect counts invocations on classes with @Repository on them. Classes in spring-data-jpa don't have that annotation --> <!-- the CallMonitoringAspect counts invocations on classes with @Repository on them. Classes in spring-data-jpa don't have that annotation -->
<!-- When using Spring Data JPA, uncomment the following: --> <!-- When using Spring Data JPA, uncomment the following: -->
<!-- <!--
<context-param> <context-param>
<param-name>spring.profiles.active</param-name> <param-name>spring.profiles.active</param-name>
<param-value>spring-data-jpa</param-value> <param-value>spring-data-jpa</param-value>
</context-param> </context-param>
--> -->
<!-- <!--
- Location of the XML file that defines the root application context. - Location of the XML file that defines the root application context.
- Applied by ContextLoaderListener. - Applied by ContextLoaderListener.
--> -->
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-config.xml, classpath:spring/tools-config.xml</param-value> <param-value>classpath:spring/business-config.xml, classpath:spring/tools-config.xml</param-value>
</context-param> </context-param>
<listener> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> </listener>
<!-- <listener>
- Servlet that dispatches request to registered handlers (Controller implementations). <listener-class>org.springframework.samples.petclinic.util.CleanUp</listener-class>
--> </listener>
<servlet> <!--
<servlet-name>petclinic</servlet-name> - Servlet that dispatches request to registered handlers (Controller implementations).
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> -->
<init-param> <servlet>
<param-name>contextConfigLocation</param-name> <servlet-name>petclinic</servlet-name>
<param-value>classpath:spring/mvc-core-config.xml</param-value> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</init-param> <init-param>
<load-on-startup>1</load-on-startup> <param-name>contextConfigLocation</param-name>
</servlet> <param-value>classpath:spring/mvc-core-config.xml</param-value>
</init-param>
<servlet-mapping> <load-on-startup>1</load-on-startup>
<servlet-name>petclinic</servlet-name> </servlet>
<url-pattern>/</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>petclinic</servlet-name>
<!-- Dandelion servlet definition and mapping --> <url-pattern>/</url-pattern>
<servlet> </servlet-mapping>
<servlet-name>dandelionServlet</servlet-name>
<servlet-class>com.github.dandelion.core.web.DandelionServlet</servlet-class> <!-- Dandelion servlet definition and mapping -->
<load-on-startup>2</load-on-startup> <servlet>
</servlet> <servlet-name>dandelionServlet</servlet-name>
<servlet-mapping> <servlet-class>com.github.dandelion.core.web.DandelionServlet</servlet-class>
<servlet-name>dandelionServlet</servlet-name> <load-on-startup>2</load-on-startup>
<url-pattern>/dandelion-assets/*</url-pattern> </servlet>
</servlet-mapping> <servlet-mapping>
<servlet-name>dandelionServlet</servlet-name>
<!-- used to provide the ability to enter Chinese characters inside the Owner Form --> <url-pattern>/dandelion-assets/*</url-pattern>
<filter> </servlet-mapping>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <!-- used to provide the ability to enter Chinese characters inside the Owner Form -->
<init-param> <filter>
<param-name>encoding</param-name> <filter-name>encodingFilter</filter-name>
<param-value>UTF-8</param-value> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</init-param> <init-param>
<init-param> <param-name>encoding</param-name>
<param-name>forceEncoding</param-name> <param-value>UTF-8</param-value>
<param-value>true</param-value> </init-param>
</init-param> <init-param>
</filter> <param-name>forceEncoding</param-name>
<param-value>true</param-value>
<filter-mapping> </init-param>
<filter-name>encodingFilter</filter-name> </filter>
<url-pattern>/*</url-pattern>
</filter-mapping> <filter-mapping>
<filter-name>encodingFilter</filter-name>
<!-- Dandelion filter definition and mapping --> <url-pattern>/*</url-pattern>
<filter> </filter-mapping>
<filter-name>dandelionFilter</filter-name>
<filter-class>com.github.dandelion.core.web.DandelionFilter</filter-class> <!-- Dandelion filter definition and mapping -->
</filter> <filter>
<filter-mapping> <filter-name>dandelionFilter</filter-name>
<filter-name>dandelionFilter</filter-name> <filter-class>com.github.dandelion.core.web.DandelionFilter</filter-class>
<url-pattern>/*</url-pattern> </filter>
</filter-mapping> <filter-mapping>
<filter-name>dandelionFilter</filter-name>
<!-- Dandelion-Datatables filter, used for basic export --> <url-pattern>/*</url-pattern>
<filter> </filter-mapping>
<filter-name>datatables</filter-name>
<filter-class>com.github.dandelion.datatables.core.web.filter.DatatablesFilter</filter-class> <!-- Dandelion-Datatables filter, used for basic export -->
</filter> <filter>
<filter-mapping> <filter-name>datatables</filter-name>
<filter-name>datatables</filter-name> <filter-class>com.github.dandelion.datatables.core.web.filter.DatatablesFilter</filter-class>
<url-pattern>/*</url-pattern> </filter>
</filter-mapping> <filter-mapping>
<filter-name>datatables</filter-name>
<!-- No need for welcome-file declaration here. <url-pattern>/*</url-pattern>
See inside spring/mvc-core-config.xml : </filter-mapping>
<mvc:view-controller path="/" view-name="welcome" />
--> <!-- No need for welcome-file declaration here.
See inside spring/mvc-core-config.xml :
</web-app> <mvc:view-controller path="/" view-name="welcome" />
-->
</web-app>