spring-context.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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:context="http://www.springframework.org/schema/context"
       xmlns:task="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/aop 
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

    <!-- 1.注解扫描器 包掃描  -->
    <context:component-scan base-package="com.chaiyi">
        <!--排除Controller注解   不扫描Controller注解-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--2.指定外部属性文件的位置/引入properties文件 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!--3. 使用jdbc数据源 连接池 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="username" value="${jdbc.username}"></property>
    </bean>

    <!--4.配置mybatis sqlsessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入数据源-->
        <property name="dataSource" ref="dataSource"></property>
        <!--关联mybatis配置文件-->
        <property name="configLocation" value="classpath:mybatis.xml"></property>
        <property name="typeAliasesPackage" value="com.chaiyi.entity"></property>
        <!--将mpper.xml的配置文件放在resources中的mappers里-->
        <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
        <!--<property name="plugins">
         <array>
            <bean class="com.github.pagehelper.PageInterceptor">
               <property name="properties"   value="mysql"></property>  鏈接mysql數據庫
            </bean>
         </array>
       </property> -->
    </bean>

    <!--5.配置jdbc事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--事务模板 编程式事务 -->
    <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
        <property name="transactionManager" ref="transactionManager"></property>
    </bean>

    <!-- 声明式事务  基于注解(事务注解驱动) -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!--定时任务注解驱动-->
    <!--	<task:annotation-driven></task:annotation-driven>-->

    <!--6.配置事务 transaction-manager:表示关联的事务管理器是谁 声明式 基于aop -->
    <tx:advice transaction-manager="transactionManager" id="txa">
        <!--事务属性配置-->
        <tx:attributes>
            <!-- find select get开头的方法为只读事务,用来提高数据库,用来提高数据库的性能
            所有添加修改删除操作不能以下列字符串开头-->
            <tx:method name="find*" read-only="true"/>
            <tx:method name="select*" read-only="true"/>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="load*" read-only="true"/>
            <tx:method name="list*" read-only="true"/>
            <tx:method name="login*" read-only="true"/>
            <!--其他的方法为默认事务-->
            <tx:method name="*" isolation="DEFAULT" propagation="REQUIRED"/>
            <!--    <tx:method name="find*"  read-only="true"/> -->
        </tx:attributes>
    </tx:advice>
    <!--7.配置aop-->
    <aop:config>
        <!--配置切点表达式  tx(pointcut),txa(txAdvice)-->
        <aop:pointcut expression="execution(* com.chaiyi.service.Impl.*.*(..))" id="tx"/>
        <!--关联事务-->
        <aop:advisor advice-ref="txa" pointcut-ref="tx"/>
    </aop:config>

    <!-- aop 切面注解 -->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>

    <!--8.扫描mapper/dao接口掃描  -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--basePackage:mapper接口所在的包-->
        <property name="basePackage" value="com.chaiyi.dao"></property>
    </bean>
    <!--9.引入spring-redis2.xml文件-->
    <import resource="classpath:spring-redis.xml"></import>
    <!--10.引入生产者spring-kafka-producer.xml文件-->
    <import resource="classpath:spring-kafka-producer.xml"></import>
    <!--11.引入消费者spring-kafka-consumer.xml文件-->
    <import resource="classpath:spring-kafka-consumer.xml"></import>
    <!--9.引入spring-es.xml文件-->
    <import resource="classpath:spring-es.xml"></import>
</beans>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大风~刮过

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值