SSM(springmvc+spring+mybatis)整合配置文件

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <!-- ===================== SpringMVC配置 ===================== -->
    <!-- 配置SpringMVC前端控制器当娱,負(fù)責(zé)處理所有請(qǐng)求 -->
    <servlet>
        <servlet-name>springDispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 加載配置文件 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:config/springmvcConfig.xml</param-value>
        </init-param>
        <!-- 隨容器啟動(dòng) -->
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- 將所有以 .action 結(jié)束請(qǐng)求铆隘,交給springMVC前端控制器處理 -->
    <servlet-mapping>
        <servlet-name>springDispatcherServlet</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>




    <!-- ===================== Spring配置 ===================== -->
    <!-- 配置spring環(huán)境 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:config/springConfig.xml</param-value>
    </context-param>

    <!-- 使用過濾器加載spring配置文件 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!-- 注冊(cè)編碼過濾器 -->
    <filter>
        <filter-name>charset</filter-name>
        <filter-class>com.project.filter.CharsetFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>charset</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

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

    <!-- 開啟自動(dòng)掃描組件 -->
    <context:component-scan
        base-package="com.project.service"></context:component-scan>

    <!-- ===================整合Mybatis=================== -->
    <!-- 配置數(shù)據(jù)庫(kù)環(huán)境 -->
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!-- mysql url -->
        <property name="url"
            value="jdbc:mysql://localhost:3306/mybaits"></property>
        <!-- 驅(qū)動(dòng) -->
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver"></property>
        <!-- 用戶名密碼 -->
        <property name="username" value="root"></property>
        <property name="password" value=""></property>
    </bean>

    <!-- 創(chuàng)建數(shù)據(jù)庫(kù)映射器授账,掃描包下所有接口,并為其創(chuàng)建動(dòng)態(tài)代理類 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.project.dao" />
    </bean>

    <!-- 配置 Mybatis 的 SqlSessionFactory -->
    <bean id="sqlSessionFactory"
        class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 指定數(shù)據(jù)庫(kù)環(huán)境 -->
        <property name="dataSource" ref="dataSource"></property>
        <!-- 指定Mybatis配置文件 -->
        <property name="configLocation"
            value="classpath:config/mybatisConfig.xml"></property>
        <!-- 指定Mybatis映射文件签则,*.xml 會(huì)匹配所有xml文件 -->
        <!-- <property name="mapperLocations" value="classpath:com/project/mapper/*.xml"></property> -->
    </bean>

    <!-- 創(chuàng)建事務(wù)管理器:針對(duì)jdbc或Mybatis的事務(wù)管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 指定環(huán)境靴庆, name的dataSource是固定寫法,ref是前面創(chuàng)建的環(huán)境id -->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

</beans>

springmvcConfig.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" 
    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/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop.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"
    > 
    
    <!-- spring包掃描功能 -->
    <context:component-scan base-package="com.project.action"/>
    
    <!-- 配置注解映射處理器 -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />

    <!-- 配置注解處理器適配器 -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean>

    <!-- 配置視圖解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- 設(shè)置視圖前綴、后綴 -->
        <property name="prefix" value="jsp/"></property>
    <!--    <property name="suffix" value=".jsp"></property> -->
    </bean>
</beans>

mabatisConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

    <settings>
        <!-- 配置log4j日志信息 -->
        <setting name="logImpl" value="LOG4J"></setting>
    </settings>
    
    <!-- 別名 -->
    <typeAliases>
        <typeAlias type="com.project.bean.UserBean" alias="UserBean" />
    </typeAliases>

    <!-- 加載映射文件混埠,也可在 spring 配置文件中加載 -->
<!--    <mappers>
        <mapper resource="com/project/mapper/UserMapper.xml" />
    </mappers> -->
</configuration>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末揍堰,一起剝皮案震驚了整個(gè)濱河市鹏浅,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌屏歹,老刑警劉巖隐砸,帶你破解...
    沈念sama閱讀 217,509評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異蝙眶,居然都是意外死亡季希,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門幽纷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來式塌,“玉大人,你說我怎么就攤上這事霹崎∩翰螅” “怎么了?”我有些...
    開封第一講書人閱讀 163,875評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵尾菇,是天一觀的道長(zhǎng)境析。 經(jīng)常有香客問我,道長(zhǎng)派诬,這世上最難降的妖魔是什么劳淆? 我笑而不...
    開封第一講書人閱讀 58,441評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮默赂,結(jié)果婚禮上沛鸵,老公的妹妹穿的比我還像新娘。我一直安慰自己缆八,他們只是感情好曲掰,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,488評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著奈辰,像睡著了一般栏妖。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上奖恰,一...
    開封第一講書人閱讀 51,365評(píng)論 1 302
  • 那天吊趾,我揣著相機(jī)與錄音宛裕,去河邊找鬼。 笑死论泛,一個(gè)胖子當(dāng)著我的面吹牛揩尸,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播屁奏,決...
    沈念sama閱讀 40,190評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼岩榆,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了了袁?” 一聲冷哼從身側(cè)響起朗恳,我...
    開封第一講書人閱讀 39,062評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎载绿,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體油航,經(jīng)...
    沈念sama閱讀 45,500評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡崭庸,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,706評(píng)論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了谊囚。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片怕享。...
    茶點(diǎn)故事閱讀 39,834評(píng)論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖镰踏,靈堂內(nèi)的尸體忽然破棺而出函筋,到底是詐尸還是另有隱情,我是刑警寧澤奠伪,帶...
    沈念sama閱讀 35,559評(píng)論 5 345
  • 正文 年R本政府宣布跌帐,位于F島的核電站,受9級(jí)特大地震影響绊率,放射性物質(zhì)發(fā)生泄漏谨敛。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,167評(píng)論 3 328
  • 文/蒙蒙 一滤否、第九天 我趴在偏房一處隱蔽的房頂上張望脸狸。 院中可真熱鬧,春花似錦藐俺、人聲如沸炊甲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽卿啡。三九已至,卻和暖如春耀石,著一層夾襖步出監(jiān)牢的瞬間牵囤,已是汗流浹背爸黄。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留揭鳞,地道東北人炕贵。 一個(gè)月前我還...
    沈念sama閱讀 47,958評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像野崇,于是被迫代替她去往敵國(guó)和親称开。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,779評(píng)論 2 354

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