springMVC web.xml 中配置加载顺序
来源:互联网 发布:雪梨开的淘宝店网址 编辑:程序博客网 时间:2024/06/05 08:44
在这里就不详细说web.xml的文件中的具体配置,就简单说明一下其中配置信息的加载顺序:
在web.xml文件中元素的加载顺序与它们在 web.xml 文件中的先后顺序无关。加载的顺序是:context-param->listener -> filter -> servlet,其中context-param,它用于向 ServletContext 提供键值对,即应用程序上下文信息。我们的 listener, filter 等在初始化时会用到这些上下文中的信息,然而对于某些配置节而言,它们出现的顺序是有先后关联的。这里在补充一下在配置中遇到的一下问题以及解决方式:
加载顺序是:首先加载Spring上下文环境配置文件,然后加载SpringMVC配置文件,并且如果配置了相同的内容,SpringMVC配置文件会被优先使用。 所以这里需要注意一个问题,一定要注意SpringMVC配置文件内容不要把Spring上下文环境配置文件内容覆盖掉。
比如在Spring上下文环境配置文件中先引入service层,然后又加入了事务:
在web.xml文件中元素的加载顺序与它们在 web.xml 文件中的先后顺序无关。加载的顺序是:context-param->listener -> filter -> servlet,其中context-param,它用于向 ServletContext 提供键值对,即应用程序上下文信息。我们的 listener, filter 等在初始化时会用到这些上下文中的信息,然而对于某些配置节而言,它们出现的顺序是有先后关联的。这里在补充一下在配置中遇到的一下问题以及解决方式:
在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>
<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
- springMVC web.xml 中配置加载顺序
- web.xml 中配置加载顺序
- SpringMVC项目中web.xml中的节点加载顺序问题
- web.xml配置加载顺序
- web.xml 文件 配置加载顺序
- web.xml的配置及加载顺序
- web.xml各个配置的加载顺序
- web.xml的配置及加载顺序
- web.xml加载顺序和配置详解
- web.xml的配置及加载顺序
- web.xml配置加载的顺序
- web.xml的配置及加载顺序
- web.xml加载顺序和配置详解
- web.xml的配置及加载顺序
- web.xml加载顺序,以及web.xml中的元素配置
- web.xml中组件加载顺序
- java web.xml中加载顺序
- web工程中web.xml元素加载顺序以及配置实例
- Springmvc中收集变量的方式 (8)
- Oracle定时更新全文索引脚本
- Python中几种数据结构的整理,列表、字典、元组、集合
- executemany存万得数据到数据库
- XML简介&DOM、PULL、SAX解析对比
- springMVC web.xml 中配置加载顺序
- 网站seo
- 剑指offer
- eclipse(springmvc+spring+hibernate)
- Android中TextView内容过长 添加滚动条进行展示
- 读书笔记--工厂方法模式
- Plug-in Item控件
- 剑指offer 序列化二叉树
- C++第五次作业