diff --git a/pom.xml b/pom.xml index 110c56cb5..5d4e99bed 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.springframework.samples spring-petclinic - 4.2.5-SNAPSHOT + 4.2.6-SNAPSHOT petclinic war @@ -17,7 +17,7 @@ UTF-8 - 2.0.5.RELEASE + 2.0.7.RELEASE 1.1.0.RELEASE @@ -96,12 +96,8 @@ - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-data-jpa + org.springframework.data + spring-data-jpa @@ -275,6 +271,7 @@ install + petclinic @@ -314,7 +311,7 @@ maven-war-plugin 2.3 - petclinic + false @@ -383,18 +380,18 @@ - - + org.codehaus.mojo cobertura-maven-plugin ${cobertura.version} - - - html - - - + + + + cobertura + + + diff --git a/readme.md b/readme.md index 5cf6aeef4..4b6a0f4cd 100644 --- a/readme.md +++ b/readme.md @@ -96,7 +96,7 @@ File -> Import -> Maven -> Existing Maven project ownersList.jsp vetList.jsp - web.xml + PetclinicInitializer.java datatables.properties @@ -135,7 +135,7 @@ File -> Import -> Maven -> Existing Maven project business-config.xml ClinicServiceJdbcTests.java - web.xml + PetclinicInitializer.java diff --git a/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java b/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java new file mode 100644 index 000000000..75d3e6320 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java @@ -0,0 +1,111 @@ +/* + * Copyright 2002-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; + +import com.github.dandelion.core.web.DandelionFilter; +import com.github.dandelion.core.web.DandelionServlet; +import com.github.dandelion.datatables.core.web.filter.DatatablesFilter; +import org.springframework.samples.petclinic.config.MvcCoreConfig; +import org.springframework.samples.petclinic.config.RootApplicationContextConfig; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.filter.CharacterEncodingFilter; +import org.springframework.web.servlet.DispatcherServlet; +import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer; + +import javax.servlet.*; +import java.util.EnumSet; + + +/** + * In Servlet 3.0+ environments, this class replaces the traditional {@code web.xml}-based approach in order to configure the + * {@link ServletContext} programmatically. + *

+ * Create the Spring "root" application context.
+ * Register a {@link DispatcherServlet} and a {@link DandelionServlet} in the servlet context.
+ * For both servlets, register a {@link CharacterEncodingFilter}, a {@link DandelionFilter} an a {@link DatatablesFilter}. + *

+ * + * @author Antoine Rey + */ +public class PetclinicInitializer extends AbstractDispatcherServletInitializer { + + /** + * Spring profile used to choose the persistence layer implementation. + *

+ * When using Spring jpa, use: jpa + * When using Spring JDBC, use: jdbc + * When using Spring Data JPA, use: spring-data-jpa + */ + private static final String SPRING_PROFILE = "jpa"; + + private static final String DANDELION_SERVLET = "dandelionServlet"; + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + super.onStartup(servletContext); + registerDandelionServlet(servletContext); + } + + @Override + protected WebApplicationContext createRootApplicationContext() { + AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext(); + rootAppContext.register(RootApplicationContextConfig.class); + rootAppContext.getEnvironment().setActiveProfiles(SPRING_PROFILE); + return rootAppContext; + } + + + @Override + protected WebApplicationContext createServletApplicationContext() { + AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext(); + webAppContext.register(MvcCoreConfig.class); + return webAppContext; + } + + @Override + protected String[] getServletMappings() { + return new String[]{"/"}; + } + + @Override + protected Filter[] getServletFilters() { + // Used to provide the ability to enter Chinese characters inside the Owner Form + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8", true); + + // Dandelion filter definition and mapping --> + DandelionFilter dandelionFilter = new DandelionFilter(); + + // Dandelion-Datatables filter, used for basic export --> + DatatablesFilter datatablesFilter = new DatatablesFilter(); + + return new Filter[]{characterEncodingFilter, dandelionFilter, datatablesFilter}; + } + + @Override + protected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) { + FilterRegistration.Dynamic registration = super.registerServletFilter(servletContext, filter); + registration.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), false, DANDELION_SERVLET); + return registration; + } + + private void registerDandelionServlet(ServletContext servletContext) { + DandelionServlet dandelionServlet = new DandelionServlet(); + ServletRegistration.Dynamic registration = servletContext.addServlet(DANDELION_SERVLET, dandelionServlet); + registration.setLoadOnStartup(2); + registration.addMapping("/dandelion-assets/*"); + } +} diff --git a/src/main/webapp/WEB-INF/jetty-web.xml b/src/main/webapp/WEB-INF/jetty-web.xml new file mode 100644 index 000000000..5bb92f033 --- /dev/null +++ b/src/main/webapp/WEB-INF/jetty-web.xml @@ -0,0 +1,7 @@ + + + + + + true + diff --git a/src/main/webapp/WEB-INF/no-spring-config-files-there.txt b/src/main/webapp/WEB-INF/no-spring-config-files-there.txt deleted file mode 100644 index 45fb7bf0a..000000000 --- a/src/main/webapp/WEB-INF/no-spring-config-files-there.txt +++ /dev/null @@ -1,4 +0,0 @@ -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 diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index f7e8652b2..6afb0f3f5 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -8,14 +8,14 @@

-