Web. XML
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:spring-mybatis.xml</param-value>
- </context-param>
- <servlet>
- <servlet-name>SpringMVC</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:spring-mvc.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- <async-supported>true</async-supported>
- </servlet>
Spring-mybatis.xml
- <bean id= "dataSource" class= "Org.apache.commons.dbcp.BasicDataSource"
- destroy-method= "Close" >
- <property name= "Driverclassname" value= "${driver}"/>
- <property name= "url" value= "${url}"/>
- <property name= "username" value= "${username}"/>
- <property name= "Password" value= "${password}"/>
- <!--Initialize connection size--
- <property name= "InitialSize" value= "${initialsize}" ></property>
- <!--maximum number of connection pools--
- <property name= "maxactive" value= "${maxactive}" ></property>
- <!--connection Pool Max free--
- <property name= "Maxidle" value= "${maxidle}" ></property>
- <!--connection Pool min free--
- <property name= "Minidle" value= "${minidle}" ></property>
- <!--get connection Maximum wait time--
- <property name= "maxwait" value= "${maxwait}" ></property>
- </bean>
- <!--spring and MyBatis are perfectly integrated without the need for MyBatis configuration mapping files--
- <bean id= "Sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >
- <property name= "dataSource" ref= "DataSource"/>
- <!--automatically scan mapping.xml files--
- <property name= "mapperlocations" value= "Classpath:com/cn/hnust/mapping/*.xml" ></property>
- </bean>
- <!--provides transactional enhancements through AOP configuration, allowing all methods of all beans under the service package to have transactions --
- <aop:config proxy-target-class= "true" >
- <aop:pointcut id= "Servicemethod"
- expression= "Execution (* com.service). *(..))" />
- <aop:advisor pointcut-ref= "Servicemethod" advice-ref= "txadvice"/>
- </aop:config>
- <tx:advice id= "txadvice" transaction-manager= "TransactionManager" >
- <tx:attributes>
- <tx:method name= "*"/>
- </tx:attributes>
- </tx:advice>
Spring-mvc.xmlMainly automatic Scan controller, view mode, annotation start-up
- <bean class= "Org.springframework.web.servlet.mvc.annotation. annotationmethodhandleradapter"/>
- <!--Configure the view resolver to parse Modelandview and strings into specific pages--
- <bean class= "Org.springframework.web.servlet.view. internalresourceviewresolver"
- P:viewclass= "Org.springframework.web.servlet.view.JstlView"
- p:prefix= "/web-inf/jsp/"
- p:suffix= ". jsp"/>
SPRINGMVC Spring MyBatis Framework Integration