Springmvc+spring+mybatis Integration:
1. Copy the required jar
2. Create a spring configuration file (beans.xml)
3. Configure the data source
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" >
<property name= "Driverclassname" value= "Com.mysql.jdbc.Driver" ></property>
<property name= "url" value= "Jdbc:mysql://127.0.0.1:3306/test" ></property>
<property name= "username" value= "root" ></property>
<property name= "password" value= "" ></property>
</bean>
4. Create an Sqlsessionfactory instance:
<bean id= "Sqlsessionfactorybean" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
<!--specify data source-
<property name= "DataSource" ref= "DataSource"/>
<!--Specify the configuration file for MyBatis--
<property name= "configlocation" value= "Classpath:mybatis-config.xml"/>
</bean>
5. Configure Transactions
<bean class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource" ></property>
</bean>
6. Configure the propagation characteristics of a transaction
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "find*" read-only= "true"/>
<tx:method name= "get*" read-only= "true"/>
<tx:method name= "query*" read-only= "true"/>
<tx:method name= "add*" propagation= "REQUIRED"/>
<tx:method name= "update*" propagation= "REQUIRED"/>
<tx:method name= "del*" propagation= "REQUIRED"/>
</tx:attributes>
</tx:advice>
7. Configuring AOP
<!--configuring AOP--
<aop:config>
<!--tangent-to-
<aop:pointcut expression= "Execution (* com.liu.service. *.*(..))" Id= "Pointcut"/>
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "Pointcut"/>
</aop:config>
8.<!--Mapping Interface--
<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "Basepackage" value= "Com.liu.mapper" ></property>
</bean>
9. Configure Dispatcherservlet
<!--Configure Spring Core controller--
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
10. Create the Springmvc-servlet.xml configuration file:
<!--note Scanner--
<context:component-scan base-package= "Com.liu"/>
<!--configuration attempt resolver--
<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/" ></property>
<property name= "suffix" value= ". JSP" ></property>
</bean>
<import resource= "Classpath:beans.xml"/>
Spring +springmvc+mybatis Portfolio Summary