https://www.cnblogs.com/hafiz/p/5875740.html

这个写的很好,是我想要的答案
http://blog.csdn.net/trigl/article/details/52073457

加载顺序是:首先加载Spring上下文环境配置文件,然后加载SpringMVC配置文件,并且如果配置了相同的内容,SpringMVC配置文件会被优先使用。
所以这里需要注意一个问题,一定要注意SpringMVC配置文件内容不要把Spring上下文环境配置文件内容覆盖掉。
比如在Spring上下文环境配置文件中先引入service层,然后又加入了事务:

<context:component-scan base-package="com.acms.service"></context:component-scan>
    <!-- define the transaction manager -->
    <bean id="transactionManagerOracle"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSourceOracle" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManagerOracle" />

但是在SpringMVC配置文件中却默认引入所有类(当然也包括service层),但是没有加入事务

<context:component-scan base-package="com.acms"></context:component-scan>

那么这时事务功能是无法起作用的,也就是代码中加入@Transactional注解是无效的。

所以为了防止这种问题一般是在Spring上下文配置文件中引入所有的类,并且加上事务:

<context:component-scan base-package="com.acms"></context:component-scan>
    <!-- define the transaction manager -->
    <bean id="transactionManagerOracle"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSourceOracle" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManagerOracle" />

而在SpringMVC配置文件中只引入controller层:

 <context:component-scan base-package="com.acms.controller" />
    <context:component-scan base-package="com.acms.*.controller" />