Spring MVC: allow static files to be handled by the default servlet handler 

Joined:
08/13/2009
Posts:
172

January 06, 2014 12:22:17    Last update: January 06, 2014 12:22:17
Add <mvc:default-servlet-handler/> to the spring servlet config (spring-servlet.xml?) so that static files can be handled by the default servlet handler. This is a full configuration file for example:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
	http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/mvc 
	http://www.springframework.org/schema/mvc/spring-mvc.xsd
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context.xsd">

	<context:component-scan base-package="com.example"/>

	<mvc:annotation-driven/>

	<mvc:interceptors>
	    <bean class="com.example.SecurityInterceptor"/>
	</mvc:interceptors>

	<mvc:default-servlet-handler/>
		
	<!-- selects a static view for rendering without the need for an 
	    explicit controller -->
     	<mvc:view-controller path="/" view-name="home"/>

	<bean id="viewResolver"
	    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
		<property name="prefix" value="/WEB-INF/jsp/"/>
		<property name="suffix" value=".jsp"/>
	</bean>
</beans>
Share |
| Comment  | Tags