Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (44 sloc) 2.55 KB
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- This file shows how to configure a a SimpleMappingExceptionResolver
via XML configuration (which is how most developers are used to seeing it
done). The equivalent Java Configuration is in the ExceptionConfiguration
class -->
<!-- The use of the "xml-config" profile here is for demonstration only.
A real application wouldn't normally need to switch between XML or Java Configuration.
You would use one, or other, or both, all the time. -->
<beans profile="xml-config">
<!-- Configure a classic SimpleMappingExceptionResolver. Try using the
ExampleSimpleMappingExceptionResolver and see the difference when /unhandledException
is invoked. -->
<bean id="simpleMappingExceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<map>
<entry key="DatabaseException" value="databaseException" />
<entry key="InvalidCreditCardException" value="creditCardError" />
</map>
</property>
<!-- Override name of exception attribute. Default is 'exception'. -->
<property name="exceptionAttribute" value="ex" />
<!-- Name of logger to use to log exceptions. Unset by default, so logging
disabled -->
<property name="warnLogCategory" value="example.MvcLogger" />
<!-- Normally Spring MVC has no default error view and this class is the
only way to define one. A nice feature of Spring Boot is the ability to provide
a very basic default error view (otherwise the application server typically
returns a Java stack trace which is not acceptable in production). See Blog
for more details. -->
<!-- To stick with the Spring Boot approach, DO NOT set this property
of SimpleMappingExceptionResolver. -->
<!-- Here we are choosing to use SimpleMappingExceptionResolver since
many Spring applications have used the approach since Spring V1. Normally
we would specify the view as "error" to match Spring Boot, however so you
can see what is happening, we are using a different page. -->
<property name="defaultErrorView" value="defaultErrorPage" />
</bean>
</beans>
</beans>