温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

spring知识点详解

发布时间:2020-06-24 01:14:30 来源:网络 阅读:484 作者:梦Scarlett 栏目:软件技术

一、spring命名空间

Spring中所有的命名空间:
下载Spring源文件,解压后会有个schema目录,里面是所有Spring模块。如下图:

spring知识点详解


spring知识点详解


二、事物配置详解

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开启事务控制的注解支持 --> 
    <!-- MyBatis自动参与到spring事务管理中,无需额外配置,
	只要org.mybatis.spring.SqlSessionFactoryBean引用的数据源
	与DataSourceTransactionManager引用的数据源一致即可,否则事务管理会不起作用。-->  
    <tx:annotation-driven transaction-manager="transactionManagerMaster" />

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI