溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

spring知識點(diǎn)詳解

發(fā)布時間:2020-06-24 01:14:30 來源:網(wǎng)絡(luò) 閱讀:498 作者:夢Scarlett 欄目:軟件技術(shù)

一、spring命名空間

Spring中所有的命名空間:
下載Spring源文件,解壓后會有個schema目錄,里面是所有Spring模塊。如下圖:

spring知識點(diǎn)詳解


spring知識點(diǎn)詳解


二、事物配置詳解

1、全注解xml文件配置

<beans xmlns="http://www.springframework.org/schema/beans"
       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/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd">

    <bean id="dataSourceMaster" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <property name="driverClassName" value="${master.jdbc.driverClass}"/>
        <property name="url" value="${master.jdbc.url}"/>
        <property name="username" value="${master.jdbc.user}"/>
        <property name="password" value="${master.jdbc.password}"/>
        <property name="filters" value="stat"/>
        <property name="maxActive" value="200"/>
        <property name="initialSize" value="0"/>
        <property name="maxWait" value="60000"/>
        <property name="minIdle" value="0"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="minEvictableIdleTimeMillis" value="300000"/>
        <property name="validationQuery" value="SELECT 'x'"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
    </bean>

    <bean id="masterSqlSessionFactory"
          class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSourceMaster"/>
        <property name="configLocation"
                  value="classpath:/mybatis/mybatis_config.xml"/>
        <property name="mapperLocations" value="classpath:mybatis/*Mapper.xml"/>
    </bean>

	<!-- mybatis mappers, scanned automatically -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.dao.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="masterSqlSessionFactory"/>
    </bean>

    <bean id="sqlSessionMaster" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
        <constructor-arg index="0" ref="masterSqlSessionFactory"/>
    </bean>
    
    <!-- spring開啟事務(wù)控制的注解支持 --> 
    <!-- MyBatis自動參與到spring事務(wù)管理中,無需額外配置,
	只要org.mybatis.spring.SqlSessionFactoryBean引用的數(shù)據(jù)源
	與DataSourceTransactionManager引用的數(shù)據(jù)源一致即可,否則事務(wù)管理會不起作用。-->  
    <tx:annotation-driven transaction-manager="transactionManagerMaster" />

    <bean id="transactionManagerMaster"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSourceMaster"/>
    </bean>
</beans>


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI