spring中ContextLoaderListener的作用
ContextLoaderListener的作用是啟動Web容器時,自動裝配ApplicationContext的配置資訊。因為它實現了ServletContextListener這個介面,在web.xml配置這個監聽器,啟動容器時,就會預設執行它實現的方法。
1、在web.xml配置監聽器ContextLoaderListener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
2、如果在web.xml中,要配置自定義位置的applicationContex.xml,則需新增以下配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
這樣配置的時候,applicationContext.xml的位置,應該在resource資料夾下面
3、如果不新增如上配置,則ContextLoaderListener會讀取applicationContext.xml的預設路徑: /WEB-INF/applicationContext.xml, 而且名字必須一樣
4、在專案中,我們的配置檔案可能不止一個,因此都採用第2種配置方式,如果有多個,中間可以用逗號隔開,完整的程式碼如下
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext. xml,application-XXX.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
相關推薦
Spring中ContextLoaderListener作用
每一個整合spring框架的專案中,總是不可避免地要在web.xml中加入這樣一段配置。 <!-- Spring配置檔案開始 --> <context-param> <param-name>contextConfigLoca
spring中ContextLoaderListener的作用
ContextLoaderListener的作用是啟動Web容器時,自動裝配ApplicationContext的配置資訊。因為它實現了ServletContextListener這個介面,在web.xml配置這個監聽器,啟動容器時,就會預設執行它實現的方
web.xml中的contextConfigLocation在spring中的作用
在web.xml中通過contextConfigLocation配置spring,contextConfigLocation引數定義了要裝入的 Spring 配置檔案。如果想裝入多個配置檔案,可以在 <param-value>標記中用逗號作分隔符。在web.xml
Spring——監聽器ContextLoaderListener作用
ContextLoaderListener作用: 在啟動Web 容器時,自動裝配 Spring applicationContext.xml 的配置資訊。 因為它實現了ServletContextListener 這個介面,在web.xml
(轉)web.xml中的contextConfigLocation在spring中的作用
param 不存在 new xml配置 prope alt 圖片 變量 -s 一、Spring如何使用多個xml配置文件 1、在web.xml中定義contextConfigLocation參數,Spring會使用這個參數去加載所有逗號分隔的xml文件,如果沒有這個參數
Spring上下文ContextLoaderListener作用
1·ContextLoaderListener 用法 ContextLoaderListener監聽器的作用就是啟動Web容器時,自動裝配ApplicationContext的配置資訊。因為它實現了ServletContextListener這個介面,在web
spring專案中監聽器作用-ContextLoaderListener
作用:在啟動Web 容器時,自動裝配Spring applicationContext.xml 的配置資訊。 因為它實現了ServletContextListener 這個介面,在web.xml 配置這個監聽器,啟動容器時,就會預設執行它實現的方法。在ContextLoad
Spring中bean的作用範圍
pre 方法 context () 釋放資源 應用 生命 產生 ron singleton作用域: Spring的scope的默認值是singleton Spring 只會為每一個bean創建一個實例,並保持bean的引用. <bean id="bean的i
Spring中Bean的五個作用域
就會 clas web應用 import 銷毀 cstring tor 默認 global 當通過spring容器創建一個Bean實例時,不僅可以完成Bean實例的實例化,還可以為Bean指定特定的作用域。Spring支持如下5種作用域: singleton:單例模式,
Spring中Bean的理解以及@Bean的作用
是把 ring con 通過 自動配置 面向對象 ava 符號 反射 一、Bean是啥 1、Java面向對象,對象有方法和屬性,那麽就需要對象實例來調用方法和屬性(即實例化); 2、凡是有方法或屬性的類都需要實例化,這樣才能具象化去使用這些方法和屬性; 3、規律:凡是子類及
易學筆記--第2章:spring中的Bean/2.3 Bean的作用域
第2章:spring中的Bean/2.3 Bean的作用域/2.3.1 單例:singleton 單例:singleton 概念:指的是所建立的Bean在整個宣告週期中都是唯一的一個物件,也就是所謂的單例模式 在宣告bean的時候如果省略則預設為預設為single
Spring中ApplicationContextAware 的作用
ApplicationContextAware 通過它Spring容器會自動把上下文環境物件呼叫ApplicationContextAware介面中的setApplicationContext方法。 我們在ApplicationContextAware的實現類中,就可以通過這個上下文環
Spring中的@Bean註解在方法上的作用
首先我們看一下這個註解的類 import org.springframework.context.annotation.Bean; @Bean("dd") public User getControllBean(){ &
Spring --17.Spring中的核心監聽器ContextLoaderListener
開發環境: JDK 1.8 Idea 2017 Tomcat:apache-tomcat-8 Spring:5.0.7 1、概述 ContextLoaderListener是Spring中的核心監聽器,當web工程啟動時, 該監聽器負責建立Spring的IOC容器,存放在Servle
Spring中Aware和Capable的區別和作用
Aware XXXAware在Spring裡表示對XXX可以感知,通俗點解釋就是:如果在某個類裡邊想要使用spring的一些東西,就可以通過實現XXXAware介面告訴Spring, Spring看到後就會給你送過來,而接收的方式是通過實現介面唯一的方法setXXX。 栗子: 比如一個類需要使用當前
在Spring 中元素的作用
一、介紹 spring的配置檔案中常包含如下元素:<context:annotation-config/>此元素的作用是向spring容器中註冊: 註冊這四個BeanPostProcessor的作用是使相應的註解起作用 1.AutowiredAnnotatio
Spring中@Import註解的作用和使用
@Import用來匯入@Configuration註解的配置類、宣告@Bean註解的bean方法、匯入ImportSelector的實現類或匯入ImportBeanDefinitionRegistra
spring中baen的生命週期,及生命週期中的作用
最近在看spring原始碼,所以總結下spring的生命週期和各個階段的作用。 spring的生命週期概括起來主要如下: 例項化 屬性注入 ioc注入 實現了BeanNameAware 則執行setBeanName方法 實現了BeanFactoryAw
Spring中Bean定義、作用域、管理問題
一、Bean的定義 <beans…/>元素是Spring配置檔案的根元素,<beans…/>元素可以包含多個<bean…/>子元素,每個<bean…/>元素可以定義一個Bean例項,每一個Bean對應Spring
第2章:spring中的Bean/2.3 Bean的作用域
易學筆記 十年IT經驗個人學習筆記分享: 開發語言:C/C++/JAVA/PYTHON/GO/JSP WEB架構:Servlets/springMVC/springBoot/springClound 容器架構:Docker容器/Docker叢集/Docker與微服務整合/