Difference between applicationContext.xml and spri

Spring lets you define multiple contexts in a parent-child hierarchy.

The applicationContext.xml defines the beans for the "root webapp context", i.e. the context associated with the webapp.

The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet‘s app context. There can be many of these in a webapp, one per Spring servlet (e.g. spring1-servlet.xml for servlet spring1spring2-servlet.xml for servlet spring2).

Beans in spring-servlet.xml can reference beans in applicationContext.xml, but not vice versa.

All Spring MVC controllers must go in the spring-servlet.xml context.

In most simple cases, the applicationContext.xml context is unnecessary. It is generally used to contain beans that are shared between all servlets in a webapp. If you only have one servlet, then there‘s not really much point, unless you have a specific use for it.

Question:

why would you have multiple spring servlets ?

it is sometimes useful to separate parts of your application that could otherwise conflict in the same context. As an example you may have ReST services and standard views, you may then have different view resolvers or security concerns for the services as to the views.

时间: 2024-11-07 15:03:49

Difference between applicationContext.xml and spri的相关文章

web.xml 配置applicationContext.xml

web.xml中classpath:和classpath*:  有什么区别? classpath:只会到你的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找. 有时候会用模糊匹配的方式配置多配置文件. 但是如果配置文件是在jar包里,模糊匹配就找不到了.可以用逗号隔开的方式配置多个配置文件. 如: <listener>  <listener-class>org.springframework.web.conte

applicationContext.xml简单笔记

applicationContext.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://

SpringMVC之application-context.xml,了解数据库相关配置

上一篇SpringMVC之web.xml让我们了解到配置一个web项目的时候,如何做基础的DispatcherServlet相关配置,作为SpringMVC上手的第一步,而application-context.xml则让我们了解到如何将数据库信息加载到项目中,包含关键的数据库连接信息.sqlSessionFactory.事务等关键因素. ①.xml内容 <?xml version="1.0" encoding="UTF-8"?> <beans x

spring的applicationContext.xml如何自动加载

一个web工程自动加载的配置文件只有web.xml,想要加载其他.xml必须在web.xml里面进行配置. 用spring的时候需要一个bean容器来管理所有的bean,所有bean默认是写在applicationContext.xml里的,在web.xml里面是这么设置的, 1 <context-param> 2 <param-name>contextConfigLocation</param-name> 3 <param-value> 4 /WEB-IN

Web环境下applicationContext.xml文件配置

在web环境下(web.xml)如何配置applicationContext.xml文件 <listener>  <listener-class>   org.springframework.web.context.ContextLoaderListener  </listener-class> </listener> 或: <servlet>  <servlet-name>context</servlet-name>  

Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope

1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.DefaultTestContext.

spring applicationContext.xml和hibernate.cfg.xml设置

applicationContext.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://ww

applicationContext.xml文件如何调用外部properties等配置文件

只需要在applicationContext.xml文件中添加一行: <!-- 导入外部的properties文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> 其中:location属性是指该文件的位置. 如果是在src目录下的话,该位置为:classpath:文件名.后缀 如果是在/WEB-INF/目录下的话,该位置为: /WEB-INF/文件名.后缀 但是要

applicationContext.xml中的使用${}是代表什么意思?

在applicationContext.xml文件中,使用 ${xxx} 表示的是:调用某个变量,该变量的名称就是{xxx}里面的"xxx". 例如:在applicationContext.xml文件中配置数据连接池 <!-- 配置数据链接池 --> <property name="dataSource"> <bean class="com.mchange.v2.c3p0.ComboPooledDataSource"