1. 程式人生 > >初學springmvc applicationContext-springmvc.xml配置檔案

初學springmvc applicationContext-springmvc.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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--掃描controller註解包-->
    <context:component-scan base-package="cn.bdqn.dxp.controller"></context:component-scan>


    <!--  啟用springmvc註解支援 -->
    <mvc:annotation-driven>
        <!--訊息轉換器-->
        <mvc:message-converters>
            <!--String型別的轉換器-->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <!--支援媒體型別-->
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=utf-8</value>
                    </list>
                </property>
            </bean>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <!-- 媒體型別:會影響到瀏覽器的解析 -->
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=utf-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!-- resources:資源 mapping:瀏覽器請求的路徑   location:專案中的路徑 -->
    <mvc:resources mapping="/**" location="/"/>


    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!--CommonsMultipartResolver實現檔案上傳,加入IOC容器-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!--上傳檔案編碼-->
        <property name="defaultEncoding" value="UTF-8"></property>
        <!--上傳單個檔案最大值,單位Byte   value=-1  無限最大值-->
        <property name="maxUploadSize" value="120000000"></property>
        <!--快取中的記憶體-->
        <property name="maxInMemorySize" value="40960"></property>
    </bean>

</beans>