有关项目业务层spring-serivce.xml的配置事物管理器的问题

来源:3-6 验证controller

哆丶哆

2019-07-31 03:56:56

老师,在构建项目环境和配置文件的时候,发现在业务层有配置事务管理器,其中有属性依赖于spring-dao.xml中配置的数据源,可是我发现这个spring-serivce.xml没有引入spring-dao.xml的依赖或者加载引用spring-dao.xml啊,为什么可以直接用这个数据源呢?

spring-serivce.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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- 扫描service包下所有使用注解的类型 -->
    <context:component-scan base-package="com.imooc.o2o.service" />

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 配置基于注解的声明式事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>


写回答

1回答

好帮手慕阿满

2019-07-31

同学你好,在web.xml中有如下的配置,将所有的spring-*.xml文件整合到一起,所以在spring-service.xml中不需要引入spring-dao.xml文件即可使用dataSource。

http://img.mukewang.com/climg/5d412b48000152e008280177.jpg

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

0

0 学习 · 8263 问题

查看课程