web.xml中定义的Spring的XML配置文件启动顺序
来源:互联网 发布:linux的版本 编辑:程序博客网 时间:2024/06/03 20:08
在web.xml中定义的Spring的配置文件一般有两个:
1、Spring上下文环境的配置文件:applicationContext.xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param>
2、SpringMVC配置文件:spring-servlet.xml
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
加载顺序是:首先加载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" />
阅读全文
0 0
- web.xml中定义的Spring的XML配置文件启动顺序
- web.xml中定义的Spring的XML配置文件启动顺序
- 关于web.xml启动spring容器的配置文件的建议
- Spring的xml配置文件的定义
- web.xml配置文件的加载顺序
- 一个spring web的配置文件web.xml
- spring的配置文件在web.xml中加载的方式
- web.xml中各组件的启动顺序
- 如何将Spring的配置文件放到web.xml中
- web.xml中引入SPRING配置文件classpath的含义
- web.xml 记载spring 配置文件的写法
- Spring web.xml的加载顺序
- spring的XML配置文件
- Spring的XML配置文件
- web.xml中配置启动spring容器的参数
- SpringMVC中web.xml的常用配置文件
- web.xml配置文件中ContextLoaderListener的作用
- web.xml文件加载顺序 一、 1 、启动一个 WEB 项目的时候, WEB 容器会去读取它的配置文件 web.xml ,读取 <listener> 和 <context-param>
- HashMap对HashCode碰撞的处理
- commbobox 初始化加载
- Codeforces 813E Army Creation [主席树]
- 析构函数与运行错误
- extractLBPFeatures
- web.xml中定义的Spring的XML配置文件启动顺序
- workerman推送
- C
- Pyinstaller打包exe
- Eclipse/MyEclipse 中常用快捷键
- LeNet模型解读
- 怎么判断个位上的数字前面有没有加0,怎么在10以下的数字前面加0
- mysql Innodb下data文件恢复方法
- linux(1)——文件类型