SPRINGMVC Spring MyBatis Framework Integration

Source: Internet
Author: User

Web. XML
    1. <context-param>
    2. <param-name>contextConfigLocation</param-name>
    3. <param-value>classpath:spring-mybatis.xml</param-value>
    4. </context-param>

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

SPRINGMVC Spring MyBatis Framework Integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.