SSM Learning-3. Adding the SPRINGMVC configuration

Source: Internet
Author: User

1. Create a new SPRINGMVC configuration file in the project Applicationcontext.xml

  

2. Basic Configuration

[1]. Configure the data source

[2]. Integration of configuration and MyBatis

[3]. Configuring the MyBatis Scanner

[4]. Transaction control Configuration

The Applicationcontext.xml is configured as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:tx= "Http://www.springframework.org/schema/tx"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"xsi:schemalocation= "Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd        Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.1.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-4.3.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring -tx-2.5.xsd ">      <!--Spring's configuration file, where the main configuration is related to the business logic -     <Context:property-placeholder Location= "Classpath:dbconfig.properties"/>     <!--Configure the data source -     <BeanID= "Poolerdatasource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource">         < Propertyname= "Jdbcurl"value= "${jdbc.jdbcurl}"></ Property>         < Propertyname= "Driverclass"value= "${jdbc.driverclass}"></ Property>         < Propertyname= "User"value= "${jdbc.user}"></ Property>         < Propertyname= "Password"value= "${jdbc.password}"></ Property>     </Bean>          <!--integration of configuration and MyBatis -     <BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean">         <!--Specify the location of the MyBatis global configuration file -         < Propertyname= "Configlocation"value= "Classpath:mybatis-config.xml"></ Property>         <!--Specify the data source -         < Propertyname= "DataSource"ref= "Poolerdatasource"></ Property>         <!--Specify the location of the MyBatis mapper file -         < Propertyname= "Mapperlocations"value= "Classpath:mapper/*.xml"></ Property>     </Bean>          <!--Configure the scanner to join the implementation of the MyBatis interface to the IOC container -     <Beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer">         <!--Scan the implementation of all DAO interfaces and add them to the IOC container -         < Propertyname= "Basepackage"value= "Com.atguigu.crud.dao"></ Property>     </Bean>          <!--configuration of transaction control -     <BeanID= "Transactionmanage"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager">         <!--Control Data Sources -         < Propertyname= "DataSource"ref= "Poolerdatasource"></ Property>         </Bean>          <!--opening annotation-based transactions, using XML configuration as a transaction -     <Aop:config>         <!--pointcut Expression -         <Aop:pointcutexpression= "execution{* com.atguigu.crud.service. *(..)}"ID= "Txpoint"/>         <!--Configuring Transaction Enhancements -         <Aop:advisorAdvice-ref= "Txadvice"Pointcut-ref= "Txpoint"/>     </Aop:config>          <!--Configure transaction enhancements, how transactions are cut into -     <Tx:adviceID= "Txadvice">         <tx:attributes>             <!--All methods are transactional methods -             <Tx:methodname="*"/>             <!--methods that start with Get are all queries -             <Tx:methodname= "get*"read-only= "true"/>         </tx:attributes>     </Tx:advice>     </Beans>

  The configuration of the dbconfig.properties is as follows:

Jdbc.jdbcurl=jdbc:mysql://localhost:mysql port number/database name jdbc.driverclass=com.mysql.jdbc.driverjdbc.user= User name jdbc.password= password

SSM Learning-3. Adding the SPRINGMVC configuration

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.