applicationContext.xml connection pool configuration druid

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http: / /www.springframework.org/schema/tx/spring-tx-4.0.xsd 
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0 .xsd " > 
    
    ! <- 1. load jdbc.properties. position -> 
    < context: Property-placeholder lOCATION =" CLASSPATH: jdbc.properties " /> 
    
    ! <- 2. druid connection pool configuration, id is fixed value, class is the full path druid connection pool class -> 
    < the bean ID = "the dataSource" class = "com.alibaba.druid.pool.DruidDataSource" > 
        <!- Basic Configuration database connection-->
        <property name="driverClassName" value="${db.driverClassName}"></property>
        <property name="url" value="${db.url}"></property>
        <property name="username" value="${db.username}"></property>
        <property name="password" value="${db.password}"></property>
    </bean>
    
    3. Integration Framework spring and mybatis    <-!
        The other objects to create SqlSession Spring container 
        id value (SqlSessionFactory) is a fixed value 
     -> 
    < the bean id = "SqlSessionFactory"  
        class = "org.mybatis.spring.SqlSessionFactoryBean" > 
        <-! . 3.1 core configuration specified mybatis location of the file -> 
        < Property name = "the configLocation"  
                value = "CLASSPATH: MyBatis / MyBatis-the config.xml" > </ Property > 
        ! <- . 3.2 configuration connection pool (data source) REF bean object point connection pool the value of the id -> 
        < Property name = "the dataSource" REF = "the dataSource" > </property>
        <!--3.3, scans all XxxMapper.xml mapping file, wherein the SQL statement is read configuration -> 
        < Property name = "the mapperLocations" value = "CLASSPATH:. MyBatis / Mapper / XML *" /> 
    </ the bean > 
    
    <-! - 4. scanner Interface mapper defined -> 
    < the bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer" > 
        <-! scan all XxxMapper interfaces, the interface instance to create a spring containers -> 
        < Property name = "basePackage"  
            value = "com.tsvv.dao" /> 
    </ the bean > 
    
    <-! . 5.Configuration package to be scanned (service layer): spring automatically to scan type in base-package,
        If @ Controller, @ Service, @ Component annotations on other classes scanned, 
        it will automatically register the class (i.e., create an instance of Spring) of the bean 
     -> 
    < context: Scan-Component 
         Base-Package = "com.tsvv .service " > 
    </ context: Scan-Component > 

</ Beans >

 

jdbc.properties:

db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql:///yonghedb?characterEncoding=utf-8
db.username=root
db.password=root

 

Guess you like

Origin www.cnblogs.com/tsvv-plus/p/11911060.html