springmvc xml

spring-beans.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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    <!-- 注解探測器 -->
    <context:component-scan base-package="com.yimi.cn.service,com.yimi.cn.conf"/>
    <context:annotation-config/>
</beans>

spring-context.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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:property-placeholder location="classpath:/conf/jdbc.properties,
    classpath:/conf/sysconfig.properties" ignore-unresolvable="true"/>

    <!-- 導(dǎo)入分割的spring配置文件 -->
    <import resource="classpath:spring/spring-beans.xml"/>
    <import resource="classpath:spring/spring-datasource.xml"/>
</beans>

spring-mvc

<?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-4.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">


    <!-- 注解探測器 -->
    <context:component-scan base-package="com.yimi.cn.controller"/>

    <mvc:annotation-driven>
        <mvc:message-converters>
            <ref bean="fastJsonHttpMessageConverter"/>
            <ref bean="stringHttpMessageConverter"/>
            <ref bean="mappingJacksonHttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>

    <!-- 配置JSON視圖 -->
    <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>application/json;charset=UTF-8</value>
            </list>
        </property>
        <property name="features">
            <array>
                <value>QuoteFieldNames</value>
                <value>WriteMapNullValue</value>
                <value>WriteNullNumberAsZero</value>
                <value>WriteNullStringAsEmpty</value>
                <value>WriteNullBooleanAsFalse</value>
                <value>WriteDateUseDateFormat</value>
                <value>PrettyFormat</value>
            </array>
        </property>
    </bean>
    <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/>
    <!-- 配置velocity引擎 -->
    <bean id="velocityConfigurer"
         class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/WEB-INF"/><!-- 模板存放的路徑 -->
        <property name="configLocation" value="classpath:conf/velocity.properties"/>
    </bean>

    <!-- 配置視圖的顯示 -->
    <bean id="ViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
        <property name="prefix" value="/vm/"/><!-- 視圖文件的前綴酱塔,即存放的路徑 -->
        <property name="suffix" value=".vm"/><!-- 視圖文件的后綴名 -->
        <property name="contentType" value="text/html;charset=UTF-8"/>
        <property name="layoutUrl" value="/layout/default.vm"/><!--指定layout文件-->
    </bean>
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="utf-8"></property>
        <property name="maxUploadSize" value="10485760000"></property>
        <property name="maxInMemorySize" value="40960"></property>
    </bean>
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <bean id="loginInterceptor" class="com.yimi.cn.controller.LoginInterCeptor"/>
        </mvc:interceptor>
    </mvc:interceptors>
    <mvc:default-servlet-handler/>
</beans>

spring-datasource.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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.2.xsd   
        http://www.springframework.org/schema/tx  
        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <property name="minIdle" value="${jdbc.minIdle}"/>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="maxWait" value="${jdbc.maxWait}"/>

        <!-- 配置間隔多久才進行一次檢測尿赚,檢測需要關(guān)閉的空閑連接照卦,單位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="180000"/>

        <!-- 配置一個連接在池中最小生存的時間消玄,單位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000"/>
        <property name="validationQuery" value="SELECT 'x'"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>

    </bean>

    <!-- 配置sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations">
            <list>
                <value>classpath:mapper/*Mapper.xml</value>
            </list>
        </property>
    </bean>

    <!-- spring管理事務(wù) -->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    
    <!-- 通過掃描的模式,自動注入bean -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.yimi.cn.mapper"/>
    </bean>

    <!-- Spring的聲明式事務(wù)管理 -->
    <!-- 設(shè)置與事務(wù)有關(guān)的各種屬性 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="select*" read-only="true"/>
            <tx:method name="is*" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
        </tx:attributes>
    </tx:advice>

    <!-- 聲明切入點 -->
    <!-- 自動創(chuàng)建事務(wù)代理 -->
    <aop:config>
        <aop:pointcut id="interceptorPointCuts" expression="execution(* com.yimi.cn.service.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts"/>
    </aop:config>
</beans>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末脚翘,一起剝皮案震驚了整個濱河市贪绘,隨后出現(xiàn)的幾起案子徘键,更是在濱河造成了極大的恐慌练对,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,542評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吹害,死亡現(xiàn)場離奇詭異螟凭,居然都是意外死亡,警方通過查閱死者的電腦和手機它呀,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,596評論 3 385
  • 文/潘曉璐 我一進店門螺男,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人纵穿,你說我怎么就攤上這事下隧。” “怎么了谓媒?”我有些...
    開封第一講書人閱讀 158,021評論 0 348
  • 文/不壞的土叔 我叫張陵淆院,是天一觀的道長。 經(jīng)常有香客問我句惯,道長土辩,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,682評論 1 284
  • 正文 為了忘掉前任抢野,我火速辦了婚禮拷淘,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘指孤。我一直安慰自己辕棚,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,792評論 6 386
  • 文/花漫 我一把揭開白布邓厕。 她就那樣靜靜地躺著逝嚎,像睡著了一般。 火紅的嫁衣襯著肌膚如雪详恼。 梳的紋絲不亂的頭發(fā)上补君,一...
    開封第一講書人閱讀 49,985評論 1 291
  • 那天,我揣著相機與錄音昧互,去河邊找鬼挽铁。 笑死伟桅,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的叽掘。 我是一名探鬼主播楣铁,決...
    沈念sama閱讀 39,107評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼更扁!你這毒婦竟也來了盖腕?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,845評論 0 268
  • 序言:老撾萬榮一對情侶失蹤浓镜,失蹤者是張志新(化名)和其女友劉穎溃列,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體膛薛,經(jīng)...
    沈念sama閱讀 44,299評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡听隐,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,612評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了哄啄。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片雅任。...
    茶點故事閱讀 38,747評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖咨跌,靈堂內(nèi)的尸體忽然破棺而出沪么,到底是詐尸還是另有隱情,我是刑警寧澤虑润,帶...
    沈念sama閱讀 34,441評論 4 333
  • 正文 年R本政府宣布成玫,位于F島的核電站加酵,受9級特大地震影響拳喻,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜猪腕,卻給世界環(huán)境...
    茶點故事閱讀 40,072評論 3 317
  • 文/蒙蒙 一冗澈、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧陋葡,春花似錦亚亲、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,828評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至岭粤,卻和暖如春惜索,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背剃浇。 一陣腳步聲響...
    開封第一講書人閱讀 32,069評論 1 267
  • 我被黑心中介騙來泰國打工巾兆, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留猎物,地道東北人。 一個月前我還...
    沈念sama閱讀 46,545評論 2 362
  • 正文 我出身青樓角塑,卻偏偏與公主長得像蔫磨,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子圃伶,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,658評論 2 350

推薦閱讀更多精彩內(nèi)容