mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
web config enhancements
- web.xml is now simpler - mvc config file has been split into 2 files
This commit is contained in:
parent
5b8ef8ea10
commit
97e1890867
4 changed files with 87 additions and 115 deletions
14
.springBeans
Normal file
14
.springBeans
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beansProjectDescription>
|
||||||
|
<version>1</version>
|
||||||
|
<pluginVersion><![CDATA[3.2.0.201301251408-M2]]></pluginVersion>
|
||||||
|
<configSuffixes>
|
||||||
|
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||||
|
</configSuffixes>
|
||||||
|
<enableImports><![CDATA[false]]></enableImports>
|
||||||
|
<configs>
|
||||||
|
<config>src/main/webapp/WEB-INF/mvc-core-config.xml</config>
|
||||||
|
</configs>
|
||||||
|
<configSets>
|
||||||
|
</configSets>
|
||||||
|
</beansProjectDescription>
|
58
src/main/webapp/WEB-INF/mvc-core-config.xml
Normal file
58
src/main/webapp/WEB-INF/mvc-core-config.xml
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
- DispatcherServlet application context for PetClinic's web tier.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/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:oxm="http://www.springframework.org/schema/oxm" xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
|
||||||
|
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.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, org.springframework.samples.petclinic.service"/>
|
||||||
|
|
||||||
|
<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 header.jsp for more details) -->
|
||||||
|
<mvc:resources mapping="/resources/**" location="/resources/"/>
|
||||||
|
|
||||||
|
<!-- uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (we're using it for Bootstrap) -->
|
||||||
|
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
|
||||||
|
|
||||||
|
<mvc:view-controller path="/" view-name="welcome"/>
|
||||||
|
|
||||||
|
|
||||||
|
<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. The default behaviour of DispatcherServlet
|
||||||
|
- is to propagate all exceptions to the servlet container: this will happen
|
||||||
|
- here with all other types of exceptions.
|
||||||
|
-->
|
||||||
|
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
|
||||||
|
<property name="defaultErrorView" value="exception"/>
|
||||||
|
<property name="warnLogCategory" value="warn"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
</beans>
|
|
@ -10,34 +10,8 @@
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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">
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
- The controllers are autodetected POJOs labeled with the @Controller annotation.
|
|
||||||
-->
|
|
||||||
<context:component-scan base-package="org.springframework.samples.petclinic.web, org.springframework.samples.petclinic.service"/>
|
|
||||||
|
|
||||||
|
|
||||||
<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 header.jsp for more details) -->
|
|
||||||
<mvc:resources mapping="/resources/**" location="/resources/"/>
|
|
||||||
|
|
||||||
<!-- uses WebJars so Javascript and CSS libs can be declared as Maven dependencies (we're using it for Bootstrap) -->
|
|
||||||
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
|
|
||||||
|
|
||||||
<mvc:view-controller path="/" view-name="welcome"/>
|
|
||||||
|
|
||||||
|
|
||||||
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
|
|
||||||
<property name="formatters">
|
|
||||||
<set>
|
|
||||||
<bean class="org.springframework.samples.petclinic.web.PetTypeFormatter" />
|
|
||||||
</set>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
- This view resolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
|
- This view resolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
|
||||||
- and uses the requested media type to pick a matching view. When the media type is 'text/html',
|
- and uses the requested media type to pick a matching view. When the media type is 'text/html',
|
||||||
- it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the
|
- it will delegate to the InternalResourceViewResolver's JstlView, otherwise to the
|
||||||
|
@ -78,28 +52,8 @@
|
||||||
-->
|
-->
|
||||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
|
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
|
||||||
p:suffix=".jsp" p:order="2"/>
|
p:suffix=".jsp" p:order="2"/>
|
||||||
|
|
||||||
<!--
|
<!-- - The AtomView rendering a Atom feed of the visits -->
|
||||||
- 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. The default behaviour of DispatcherServlet
|
|
||||||
- is to propagate all exceptions to the servlet container: this will happen
|
|
||||||
- here with all other types of exceptions.
|
|
||||||
-->
|
|
||||||
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
|
|
||||||
<property name="defaultErrorView" value="exception"/>
|
|
||||||
<property name="warnLogCategory" value="warn"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- - The AtomView rendering a Atom feed of the visits -->
|
|
||||||
|
|
||||||
<bean id="visitsList" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
|
<bean id="visitsList" class="org.springframework.samples.petclinic.web.VisitsAtomView"/>
|
||||||
|
|
||||||
<bean id="vets/vetsList" class="org.springframework.web.servlet.view.xml.MarshallingView">
|
<bean id="vets/vetsList" class="org.springframework.web.servlet.view.xml.MarshallingView">
|
|
@ -1,39 +1,22 @@
|
||||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
id="WebApp_ID" version="2.5">
|
||||||
|
|
||||||
<display-name>Spring PetClinic</display-name>
|
<display-name>Spring PetClinic</display-name>
|
||||||
|
|
||||||
<description>Spring PetClinic sample application</description>
|
<description>Spring PetClinic sample application</description>
|
||||||
|
|
||||||
<!--
|
|
||||||
Key of the system property that should specify the root directory of this
|
|
||||||
web app. Applied by WebAppRootListener or Log4jConfigListener.
|
|
||||||
-->
|
|
||||||
<context-param>
|
|
||||||
<param-name>webAppRootKey</param-name>
|
|
||||||
<param-value>petclinic.root</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<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>
|
||||||
<!-- you can replace the above param with:
|
<!-- Available profiles:
|
||||||
<param-value>jdbc</param-value>
|
<param-value>jdbc</param-value>
|
||||||
<param-value>jpa</param-value> (in the case of plain JPA)
|
<param-value>jpa</param-value> (in the case of plain JPA)
|
||||||
<param-value>spring-data-jpa</param-value> (in the case of Spring Data JPA)
|
<param-value>spring-data-jpa</param-value> (in the case of Spring Data JPA)
|
||||||
-->
|
-->
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
<!--
|
|
||||||
Location of the Log4J config file, for initialization and refresh checks.
|
|
||||||
Applied by Log4jConfigListener.
|
|
||||||
-->
|
|
||||||
<context-param>
|
|
||||||
<param-name>log4jConfigLocation</param-name>
|
|
||||||
<param-value>/WEB-INF/classes/log4j.xml</param-value>
|
|
||||||
</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 ContextLoaderServlet.
|
- Applied by ContextLoaderServlet.
|
||||||
|
@ -41,66 +24,33 @@
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextConfigLocation</param-name>
|
<param-name>contextConfigLocation</param-name>
|
||||||
<param-value>classpath:spring/applicationContext-dao.xml</param-value>
|
<param-value>classpath:spring/applicationContext-dao.xml</param-value>
|
||||||
<!--
|
|
||||||
To use the JPA variant above, you will need to enable Spring load-time
|
|
||||||
weaving in your server environment. Out of the box, Spring will try to
|
|
||||||
detect the running environment and use the appropriate weaver but if that
|
|
||||||
fails, one must enable one by hand or use the VM-wide weaver.
|
|
||||||
See PetClinic's readme and/or Spring's JPA documentation for more information.
|
|
||||||
-->
|
|
||||||
</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>
|
||||||
|
|
||||||
<!--
|
|
||||||
- Configures Log4J for this web app.
|
|
||||||
- As this context specifies a context-param "log4jConfigLocation", its file path
|
|
||||||
- is used to load the Log4J configuration, including periodic refresh checks.
|
|
||||||
-
|
|
||||||
- Would fall back to default Log4J initialization (non-refreshing) if no special
|
|
||||||
- context-params are given.
|
|
||||||
-
|
|
||||||
- Exports a "web app root key", i.e. a system property that specifies the root
|
|
||||||
- directory of this web app, for usage in log file paths.
|
|
||||||
- This web app specifies "petclinic.root" (see log4j.properties file).
|
|
||||||
-->
|
|
||||||
<!-- Leave the listener commented-out if using JBoss -->
|
|
||||||
<!--
|
|
||||||
<listener>
|
|
||||||
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
|
|
||||||
</listener>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
- Servlet that dispatches request to registered handlers (Controller implementations).
|
- Servlet that dispatches request to registered handlers (Controller implementations).
|
||||||
- Has its own application context, by default defined in "{servlet-name}-servlet.xml",
|
|
||||||
- i.e. "petclinic-servlet.xml".
|
|
||||||
-
|
|
||||||
- A web app can contain any number of such servlets.
|
|
||||||
- Note that this web app has a shared root application context, serving as parent
|
|
||||||
- of all DispatcherServlet contexts.
|
|
||||||
-->
|
-->
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>petclinic</servlet-name>
|
<servlet-name>petclinic</servlet-name>
|
||||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>contextConfigLocation</param-name>
|
||||||
|
<param-value>/WEB-INF/mvc-core-config.xml</param-value>
|
||||||
|
</init-param>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<!--
|
|
||||||
- Maps the petclinic dispatcher to "*.do". All handler mappings in
|
|
||||||
- petclinic-servlet.xml will by default be applied to this subpath.
|
|
||||||
- If a mapping isn't a /* subpath, the handler mappings are considered
|
|
||||||
- relative to the web app root.
|
|
||||||
-
|
|
||||||
- NOTE: A single dispatcher can be mapped to multiple paths, like any servlet.
|
|
||||||
-->
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>petclinic</servlet-name>
|
<servlet-name>petclinic</servlet-name>
|
||||||
<url-pattern>/</url-pattern>
|
<url-pattern>/</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- used so we can use forms of method type 'PUT' and 'DELETE'
|
||||||
|
see here: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/view.html#rest-method-conversion
|
||||||
|
-->
|
||||||
<filter>
|
<filter>
|
||||||
<filter-name>httpMethodFilter</filter-name>
|
<filter-name>httpMethodFilter</filter-name>
|
||||||
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
|
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
|
||||||
|
@ -110,9 +60,5 @@
|
||||||
<filter-name>httpMethodFilter</filter-name>
|
<filter-name>httpMethodFilter</filter-name>
|
||||||
<servlet-name>petclinic</servlet-name>
|
<servlet-name>petclinic</servlet-name>
|
||||||
</filter-mapping>
|
</filter-mapping>
|
||||||
|
|
||||||
<session-config>
|
|
||||||
<session-timeout>10</session-timeout>
|
|
||||||
</session-config>
|
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
Loading…
Reference in a new issue