SSM整合步驟
1,建立spring.xml
去課件資料找頭標籤
~~~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:p="http://www.springframework.org/schema/p" 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-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
~~~
2.建立掃描包
~~~xml
<context:component-scan base-package="com.znsd.examination" />
~~~
3 引入資原始檔
~~~xml
<context:property-placeholder location="classpath:jdbc.properties" />
~~~
4,建立c3p0連線池
~~~xml
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
<!-- 佇列中的最小連線數 -->
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<!-- 佇列中的最大連線數 -->
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<!-- 當連線耗盡時建立的連線數 -->
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
<!-- 等待時間 -->
<property name="checkoutTimeout" value="${c3p0.checkoutTimeout}"></property>
<!-- 初始化連線數 -->
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<!-- 最大空閒時間,超出時間連線將被丟棄 -->
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<!-- 每隔60秒檢測空閒連線 -->
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property>
</bean>
~~~
5.引入sessionFactory 掃描.dao.xml ,依賴datasource
~~~xml
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations">
<list>
<!-- 自動掃描mapper.xml檔案 *資料夾下表示所有檔案,也可以單獨在mybatis-config.xml中單獨配置 -->
<value>classpath:testmapping/*.xml</value>
</list>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
~~~
6,注入mybatis , 依賴baseDao ,指定註解 DAO註解
~~~xml
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- mybatis 介面包(如果有多個可以用,逗號隔開) -->
<property name="basePackage" value="com.znsd.examination.dao" />
<!-- sqlSession工廠beanId -->
<property name="sqlSessionFactoryBeanName" value="sessionFactory" />
<!-- 指定dao層介面的註解 -->
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
</bean>
~~~
7,開啟事物管理器,
~~~xml
<!-- 定義事務管理器(宣告式的事務) -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
~~~
8匯入maven jar
~~~xml
<properties>
<!-- spring版本號 -->
<spring.version>4.1.3.RELEASE</spring.version>
<!-- mybatis版本號 -->
<mybatis.version>3.2.8</mybatis.version>
<!-- log4j日誌檔案管理包版本 -->
<slf4j.version>1.6.4</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<!-- json版本號 -->
<jackson.version>2.2.3</jackson.version>
<struts.version>2.3.24.1</struts.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- struts -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.24.1</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.24.1</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.24.1</version>
</dependency>
<!-- c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.2.1</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.webflow</groupId> -->
<!-- <artifactId>org.springframework.webflow</artifactId> -->
<!-- <version>2.0.5.RELEASE</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
<version>2.3.24.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<!-- mybatis 包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!--mybatis spring 外掛 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mysql連線 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- 資料來源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.4</version>
</dependency>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- 檔案上傳 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
~~~
相關文章
- ssm整合SSM
- SSM學習筆記3——整合 SpringMVC、整合SSMSSM筆記SpringMVC
- SSM框架整合SSM框架
- 整合SSM框架SSM框架
- SSM整合開發SSM
- SpringMVC-整合SSMSpringMVCSSM
- SSM框架的整合SSM框架
- 八、SpringMVC——ssm整合SpringMVCSSM
- ssm整合(maven版本)SSMMaven
- ssm整合詳解SSM
- SSM整合(Spring、SpringMVC、Mybatis)SSMSpringMVCMyBatis
- ssm框架整合筆記SSM框架筆記
- SSM——Spring整合SpringMVC,MyBatisSSMSpringMVCMyBatis
- SSM框架整合流程SSM框架
- SSM框架整合開發SSM框架
- SSM(SpringMVC + Spring + Mybatis)整合SSMSpringMVCMyBatis
- SSM整合之CRUD環境搭建整合SSM
- Spring整合Mybatis的一般步驟(IDEA版)SpringMyBatisIdea
- Mybatis20_ssm整合10MyBatisSSM
- ssm高階整合 尚矽谷SSM
- SSM專案整合——後端SSM後端
- SSM框架整合(配置檔案)SSM框架
- Mybatis整合Spring(ssm整合待續)-day04MyBatisSpringSSM
- 使用xml檔案配置SSM整合XMLSSM
- mybatis與spring整合ssm01MyBatisSpringSSM
- SpringMVC(3)- 校驗框架、SSM整合SpringMVC框架SSM
- Maven整合SSM和Redis,親測MavenSSMRedis
- 【Java】SSM框架整合 附原始碼JavaSSM框架原始碼
- 怎麼進行資料整合?必要步驟有什麼?
- 操作步驟
- 融雲IM乾貨丨在SwiftUI中整合IMKit,整合IMKit的基本步驟有哪些SwiftUI
- SSM框架整合——書籍管理系統SSM框架
- SSM三大框架整合詳細教程SSM框架
- 3個步驟輕鬆整合Push Kit,實現App訊息推送APP
- 海豚星空掃碼投屏 Android 接收端 SDK 整合 六步驟Android
- vnc安裝步驟,vnc安裝步驟詳解VNC
- ssm框架整合redis(demo)---通過cache方式SSM框架Redis
- 專案步驟