ssm

applicationContext.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"
       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.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/aop
                   http://www.springframework.org/schema/aop/spring-aop.xsd
                    http://www.springframework.org/schema/tx
                     http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 開啟注解掃描雹有,要掃描的是service和dao層的注解疫赎,要忽略web層注解桥嗤,因為web層讓SpringMVC框架 去管理 -->
    <context:component-scan base-package="cn.itcast">
        <!-- 所以添加下列配置柬焕,告訴它要忽略的注解 annotation代表這注解。 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>




    <!--spring整合Mybatis框架-->

        <!--配置連接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="com.mysql.jdbc.Driver" />
            <property name="jdbcUrl" value="jdbc:mysql:///ssm" />
            <property name="user" value="root" />
            <property name="password" value="root" />
    </bean>

    <!--配置SqlsessionFactory工廠-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
    </bean>

        <!--配置AccountDao接口所在的包-->
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.itcast.dao"/>
    </bean>



    <!--配置spring聲明式事務管理-->
    <!--配置事務管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--配置事務通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="*" isolation="DEFAULT"/>
        </tx:attributes>
    </tx:advice>

    <!--配置AOP增強-->
    <aop:config>
        <aop:advisor advice-ref="txAdvice" pointcut="execution( * cn.itcast.service.Impl.*ServiceImpl.*(..))"/>
    </aop:config>
</beans>

log4j.properties

# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE            debug   info   warn error fatal
log4j.rootCategory=info, CONSOLE, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=d:\axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout

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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" 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/context
              http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/aop
                   http://www.springframework.org/schema/aop/spring-aop.xsd
                    http://www.springframework.org/schema/tx
                     http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">


    <!--開啟注解掃描 只掃描Controller注解-->
    <context:component-scan base-package="cn.itcast">
        
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--配置視圖解析器對象-->
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- JSP文件所在的目錄 -->
        <property name="prefix" value="/WEB-INF/pages/"/>
        <!-- 文件的后綴名 -->
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--過濾靜態(tài)資源-->
    <mvc:resources location="/css/" mapping="/css/**" />
    <mvc:resources location="/images/" mapping="/images/**" />
    <mvc:resources location="/js/" mapping="/js/**" />


    <!--開啟SpringMVC注解的支持-->
    <mvc:annotation-driven/>
</beans>

webapp---WEB-INF----web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>

  <!--配置spring的監(jiān)聽器 默認只加載WEB-INF目錄下的applicationContext.xml文件 別的加載不到-->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
  <!--所以需要更改配置文件的路徑-->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
</context-param>
  <context-param>
    <param-name/>
    <param-value/>
  </context-param>
  <context-param>
    <param-name/>
    <param-value/>
  </context-param>


  <!--配置前端控制器-->
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--加載springMVC.xml的配置文件-->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <!--啟動服務器就創(chuàng)建該servlet-->
<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 配置解決中文亂碼的過濾器 -->
  <filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
  <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末册烈,一起剝皮案震驚了整個濱河市倘屹,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌变姨,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件厌丑,死亡現(xiàn)場離奇詭異定欧,居然都是意外死亡渔呵,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進店門砍鸠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來扩氢,“玉大人,你說我怎么就攤上這事爷辱÷疾颍” “怎么了?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵饭弓,是天一觀的道長双饥。 經(jīng)常有香客問我,道長示启,這世上最難降的妖魔是什么兢哭? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮夫嗓,結果婚禮上迟螺,老公的妹妹穿的比我還像新娘。我一直安慰自己舍咖,他們只是感情好矩父,可當我...
    茶點故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著排霉,像睡著了一般窍株。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上攻柠,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天球订,我揣著相機與錄音,去河邊找鬼瑰钮。 笑死冒滩,一個胖子當著我的面吹牛,可吹牛的內容都是我干的浪谴。 我是一名探鬼主播开睡,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼苟耻!你這毒婦竟也來了篇恒?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤凶杖,失蹤者是張志新(化名)和其女友劉穎胁艰,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡蝗茁,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年醋虏,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片哮翘。...
    茶點故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖毛秘,靈堂內的尸體忽然破棺而出饭寺,到底是詐尸還是另有隱情,我是刑警寧澤叫挟,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布艰匙,位于F島的核電站,受9級特大地震影響抹恳,放射性物質發(fā)生泄漏员凝。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一奋献、第九天 我趴在偏房一處隱蔽的房頂上張望健霹。 院中可真熱鬧,春花似錦瓶蚂、人聲如沸糖埋。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽瞳别。三九已至,卻和暖如春杭攻,著一層夾襖步出監(jiān)牢的瞬間祟敛,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工兆解, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留馆铁,地道東北人。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓痪宰,卻偏偏與公主長得像叼架,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子衣撬,可洞房花燭夜當晚...
    茶點故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內容