​ SSM整合步驟

悟空程式設計師發表於2018-09-23
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> ~~~      


相關文章