Configuration of the 1.web.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.5"
Xmlns= "Http://java.sun.com/xml/ns/javaee"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<!--context parameters (first boot), specifying the JDBC configuration file location--
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/config/jdbc.xml</param-value>
</context-param>
<!--Spring Listener (second boot), monitor SPRINGMVC environment--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--SPRINGMVC Encoded interceptor (third boot), SPRINGMVC built-in codec blocker--
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--SPRINGMVC Front Controller (fourth start), which passes through this master controller before distributing other controllers--
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/config/springmvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!--website default home--
<welcome-file-list>
<welcome-file>begin.jsp</welcome-file>
</welcome-file-list>
</web-app>
Configuration file for 2.spring Applicationcontext-mybatis.xml
<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:mybatis-spring= "http://mybatis.org/schema/ Mybatis-spring "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:jee=" http://www.springframework.org/ Schema/jee "xmlns:tx=" Http://www.springframework.org/schema/tx "xmlns:context=" http://www.springframework.org/ Schema/context "xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xsi:schemalocation="/HTTP/ Www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX http://www.springframework.org/schema/tx/spring-tx-3.0.xsd/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd/HTTP Mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd " Default-lazy-init= "true"; <context:component-scan base-package= "Com.ltf.springmvc"/> <bean id= "sqlsessionfactory" class= " Org.mybatis.spring.SqlSessionFactoryBean "lazy-init=" false "> <property name=" dataSource "ref=" Datasour Ce "/> <property name=" mapperlocations "value=" Classpath:sqlmapper/*mapper.xml "/> <property nam E= "Configlocation" value= "Classpath:mybatis/mybatis-config.xml"/> </bean> <bean id= "sqlsession" class= " Org.mybatis.spring.SqlSessionTemplate "scope=" prototype "> <constructor-arg index=" 0 "ref=" Sqlsessionfa Ctory "/> </bean> <bean class=" Org.mybatis.spring.mapper.MapperScannerConfigurer "> <propert Y name= "basepackage" value= "Com.ltf.springmvc.dao"/> <property name= "sqlsessionfactorybeanname" value= "sqlSe Ssionfactory "></property> </bean> <mybatis-spring:scan base-package=" Com.ltf.springmvc.dao "/ ></beans>
Configuration of 3.JDBC
<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:tx="/HTTP/ Www.springframework.org/schema/tx "xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xsi:schemalocation=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.0.xsd/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-4.0.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd " > <!--Introducing the JDBC configuration file--<context:property-placeholder location= "Classpath:config/jdbc.properties"/> <bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > <PROperty name= "Driverclassname" > <value>${jdbc_driverClassName}</value> </property> <property name= "url" > <value>${jdbc_url}</value> </property> <PR Operty name= "username" > <value>${jdbc_username}</value> </property> <prop Erty name= "Password" > <value>${jdbc_password}</value> </property> <!--connection Pool Maximum usage connections--<property name= "maxactive" > <value>20</value> </property> <!--Initialize connection size-<property name= "InitialSize" > <value>1</value> & Lt;/property> <!--get connection maximum wait time-<property name= "maxwait" > <value>60000< /value> </property> <!--connection Pool Max idle--<property name= "Maxidle" > <va Lue>20</value> </property> <!--connection Pool min Idle--<property name= "Minidle" > <value>3< ;/value> </property> <!--automatic removal of useless connections-<property name= "removeabandoned" > <value>true</value> </property> <!--waiting time to clear unwanted connections-<property name= "R Emoveabandonedtimeout "> <value>180</value> </property> <!--connection Properties-- <property name= "ConnectionProperties" > <value>clientEncoding=UTF-8</value> </ Property> </bean>
<!--data source transaction Management- <bean id= "Txmanager" class= " Org.springframework.jdbc.datasource.DataSourceTransactionManager "> <property name=" DataSource "ref=" DataSource "/> </bean> <!--auto-scan component, need to remove controller, otherwise affect transaction management- <context: Component-scan base-package= "Com.springmvc" > <context:exclude-filter type= "regex" expression= " com.spring.web.* "/> </context:component-scan>
</beans>
4.jdbc.properties
jdbc_driverclassname=com.mysql.jdbc.driverjdbc_url=jdbc:mysql://localhost:3306/demo?useunicode=true& characterencoding=utf-8jdbc_username=rootjdbc_password=123456
5.SPRINGMVC Configuration
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= " Http://www.springframework.org/schema/context "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xsi:s chemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org /schema/beans/spring-beans-3.0.xsd Http://www.springframework.org/schema/context HTTP://WW W.springframework.org/schema/context/spring-context-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC Http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> < scan all controller--> at startup!-- ; <context:component-scan base-package= "Com.springmvc.web"/> <!--mainly acts on the @controller, activates the mode, the following is a shorthand form, fully can be manually equipped with Replace this shorthand form, it will automatically register DefaulTannotationhandlermapping and Annotationmethodhandleradapter, is the spring MVC required for @controllers distribution requests--and <MVC: Annotation-driven/> <!--configuration js,css such as static files are mapped directly to the corresponding folder, not dispatcherservlet processed--<mvc:resources location = "/web-inf/resources/**" mapping= "/resources"/> <!--JSP page parser, when the controller returns the XXX string, first through the interceptor, then the class will be in the/web-inf/v iews/directory, find xxx.jsp files--<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" value= "/views/"/> <property name= "suffix" value= ". jsp"/> </ Bean> </beans>
"Source Address acquisition
SPRINGMVC + mybatis Integration details, and the problems encountered, please refer to the following information:
Resources:
Http://www.springmvc,net/detail/6074493.html
http://my.spring.net/wangbiglei/blog/489583
http://my.springmvc.net/wangbiglei/blog/489604
Configuration of the Spring+mybatis+springmvc