Skip to content
Snippets Groups Projects
Commit a6e81a51 authored by Antoine Rey's avatar Antoine Rey
Browse files

#164 Spring Boot version of Petclinic ready to deploy to an external web container (ie Tomcat)

parent 76a4ca33
No related branches found
No related tags found
No related merge requests found
Showing
with 22 additions and 355 deletions
<?xml version="1.0" encoding="UTF-8"?>
<!--
- DispatcherServlet application context for PetClinic's web tier.
-->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="mvc-view-config.xml"/>
<!--
- POJOs labeled with the @Controller and @Service annotations are auto-detected.
-->
<context:component-scan
base-package="org.springframework.samples.petclinic.web"/>
<mvc:annotation-driven conversion-service="conversionService"/>
<!-- all resources inside folder src/main/webapp/resources are mapped so they can be refered to inside JSP files
(see htmlHeader.jsp for more details) -->
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:resources mapping="/vendors/**" location="/vendors/"/>
<mvc:view-controller path="/" view-name="welcome"/>
<!-- serve static resources (*.html, ...) from src/main/webapp/
Required when both servlet-mapping is '/' and static resources need to be served -->
<mvc:default-servlet-handler/>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="org.springframework.samples.petclinic.web.PetTypeFormatter"/>
</set>
</property>
</bean>
<!--
- Message source for this context, loaded from localized "messages_xx" files.
- Files are stored inside src/main/resources
-->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="messages/messages"/>
<!--
- This bean resolves specific types of exceptions to corresponding logical
- view names for error views.
-->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<!-- view name resolved using bean of type InternalResourceViewResolver (declared in mvc-view-config.xml) -->
<property name="defaultErrorView" value="exception"/>
<!-- results into 'WEB-INF/jsp/exception.jsp' -->
<property name="warnLogCategory" value="warn"/>
<!-- needed otherwise exceptions won't be logged anywhere -->
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!--
- DispatcherServlet application context for PetClinic's web tier.
-->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
- The ContentNegotiatingViewResolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
- and uses the requested media type (determined by the path extension) to pick a matching view.
- When the media type is 'text/html', it will delegate to the InternalResourceViewResolver's JstlView,
- otherwise to the BeanNameViewResolver.
-->
<mvc:view-resolvers>
<mvc:content-negotiation use-not-acceptable="true">
<mvc:default-views>
<bean class="org.springframework.web.servlet.view.JstlView">
<property name="url" value=""/>
</bean>
</mvc:default-views>
</mvc:content-negotiation>
<!-- Registering BeanNameViewResolver and InternalViewResolver -->
<mvc:bean-name/>
<mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp"/>
</mvc:view-resolvers>
<!-- Renders an XML view. Used by the BeanNameViewResolver -->
<bean id="vets/vetList.xml" class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller" ref="marshaller"/>
</bean>
<oxm:jaxb2-marshaller id="marshaller">
<!-- Object-XML mapping declared using annotations inside 'Vets' -->
<oxm:class-to-be-bound name="org.springframework.samples.petclinic.model.Vets"/>
</oxm:jaxb2-marshaller>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Application context definition for PetClinic on JPA.
-->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--
Simply defining this bean will cause requests to owner names to be saved.
This aspect is defined in petclinic.jar's META-INF/aop.xml file.
Note that we can dependency inject this bean like any other bean.
-->
<aop:aspectj-autoproxy>
<aop:include name="callMonitor"/>
</aop:aspectj-autoproxy>
<!-- Call monitoring aspect that monitors call count and call invocation time -->
<bean id="callMonitor" class="org.springframework.samples.petclinic.util.CallMonitoringAspect"/>
<!--
Exporter that exposes the CallMonitoringAspect via JMX,
based on the @ManagedResource, @ManagedAttribute, and @ManagedOperation annotations.
-->
<context:mbean-export/>
<!-- enables scanning for @Cacheable annotation -->
<cache:annotation-driven/>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache"/>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:cache/ehcache.xml"/>
</bean>
</beans>
......@@ -6,7 +6,7 @@
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
<html lang="en">
<jsp:include page="fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="error"/>
......@@ -28,7 +28,7 @@
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="fragments/footer.jsp"/>
<petclinic:footer/>
</body>
</html>
......@@ -11,7 +11,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="owners"/>
......@@ -44,7 +44,7 @@
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
</body>
</html>
......@@ -9,7 +9,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="owners"/>
......@@ -45,7 +45,7 @@
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
</body>
</html>
......@@ -10,7 +10,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="owners"/>
......@@ -109,7 +109,7 @@
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
</body>
......
......@@ -10,7 +10,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="owners"/>
......@@ -44,7 +44,7 @@
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
</body>
</html>
......@@ -9,7 +9,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="owners"/>
......@@ -53,7 +53,7 @@
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
<script>
$(function () {
......
......@@ -11,7 +11,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
......@@ -72,7 +72,7 @@
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
<script>
$(function () {
$("#date").datepicker({dateFormat: 'yy/mm/dd'});
......
......@@ -9,7 +9,7 @@
<html lang="en">
<jsp:include page="../fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader />
<body>
<petclinic:bodyHeader menuName="vets"/>
......@@ -44,7 +44,7 @@
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="../fragments/footer.jsp"/>
<petclinic:footer />
</body>
</html>
......@@ -8,7 +8,7 @@
<html lang="en">
<jsp:include page="fragments/htmlHeader.jsp"/>
<petclinic:htmlHeader/>
<body>
<petclinic:bodyHeader menuName="home"/>
......@@ -26,7 +26,7 @@
<petclinic:pivotal/>
</div>
</div>
<jsp:include page="fragments/footer.jsp"/>
<petclinic:footer/>
</body>
</html>
All Spring config files (including Spring MVC ones) are inside src/main/resource.
There are mostly 2 reasons to that:
- All Spring config files are grouped into one single place
- It is simpler to reference them from inside JUnit tests
\ No newline at end of file
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="name" required="true" rtexprvalue="true"
description="Name of the active menu: home, owners, vets or error" %>
......
<?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_3_0.xsd"
version="3.0" metadata-complete="true">
<display-name>Spring PetClinic</display-name>
<description>Spring PetClinic sample application</description>
<!-- When using Spring jpa, use the following: -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>jpa</param-value>
</context-param>
<!-- When using Spring JDBC, use the following: -->
<!-- <context-param>
<param-name>spring.profiles.active</param-name>
<param-value>jdbc</param-value>
</context-param> -->
<!-- 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: -->
<!--
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>spring-data-jpa</param-value>
</context-param>
-->
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderListener.
-->
<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 servlet definition and mapping -->
<servlet>
<servlet-name>dandelionServlet</servlet-name>
<servlet-class>com.github.dandelion.core.web.DandelionServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dandelionServlet</servlet-name>
<url-pattern>/dandelion-assets/*</url-pattern>
</servlet-mapping>
<!-- used to provide the ability to enter Chinese characters inside the Owner Form -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Dandelion filter definition and mapping -->
<filter>
<filter-name>dandelionFilter</filter-name>
<filter-class>com.github.dandelion.core.web.DandelionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>dandelionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Dandelion-Datatables filter, used for basic export -->
<filter>
<filter-name>datatables</filter-name>
<filter-class>com.github.dandelion.datatables.core.web.filter.DatatablesFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>datatables</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- No need for welcome-file declaration here.
See inside spring/mvc-core-config.xml :
<mvc:view-controller path="/" view-name="welcome" />
-->
</web-app>
/*
* Copyright 2002-2013 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.service;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p> Integration test using the jdbc profile.
*
* @author Thomas Risberg
* @author Michael Isvy
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
*/
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jdbc")
public class ClinicServiceJdbcTests extends AbstractClinicServiceTests {
}
package org.springframework.samples.petclinic.service;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p> Integration test using the jpa profile.
*
* @author Rod Johnson
* @author Sam Brannen
* @author Michael Isvy
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
*/
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jpa")
public class ClinicServiceJpaTests extends AbstractClinicServiceTests {
}
package org.springframework.samples.petclinic.service;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.samples.petclinic.PetClinicApplication;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
......@@ -12,9 +14,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
*/
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
@SpringApplicationConfiguration(classes = PetClinicApplication.class)
public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment