名稱:example-servlet.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd" >
<!-- 默認的注解映射的支持 -->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 如果當前請求為“/”時,則轉(zhuǎn)發(fā)到“/index” -->
<mvc:view-controller path="/" view-name="forward:/index" />
<!-- 靜態(tài)資源映射 -->
<mvc:resources mapping="js/**" location="/static/js/" />
<mvc:resources mapping="css/**" location="/static/css/" />
<mvc:resources mapping="fonts/**" location="/static/fonts/" />
<mvc:resources mapping="plugins/**" location="/static/plugins/" />
<mvc:resources mapping="images/**" location="/static/images/" />
<!-- 當上面要訪問的靜態(tài)資源不包括在上面的配置中時落包,則根據(jù)此配置來訪問 -->
<mvc:default-servlet-handler/>
<!-- 開啟controller注解支持 -->
<!-- use-default-filters="false" 只掃描指定的注解 -->
<context:component-scan base-package="com.troyforever.example.mvc.controller" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 視圖解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="contentType" value="text/html"/>
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>