spring框架里面applicationContext.xml 和spring-servlet.xml 的區別

問題:spring框架里面applicationContext.xml 和spring-servlet.xml 的區別

  • 在Spring框架中applicationContext.xml和Spring -servlet.xml有任何關系嗎?

  • DispatcherServlet可以使用到在applicationContext.xml中聲明的屬性文件嗎?

  • 另外,為什么我需要*-servlet.xml呢?為什么只有applicationContext.xml是不夠的?

回答一

Spring允許您在parent-child這個層級結構中定義多個上下文。

applicationContext.xml定義了“root webapp context”的beans,即與webapp關聯的上下文。

spring-servlet.xml(你想叫什么都行)定義了一個servlet的應用程序上下文的bean。在一個webapp(一個Spring servlet)中可能有很多這樣的文件(例如:servlet spring1的spring1 .xml,servlet spring2的spring2 .xml)。

spring-servlet.xml中的bean可以引用applicationContext.xml中的bean,但反之則不行。

所有Spring MVC控制器都必須放在Spring -servlet.xml上下文中。

在大多數簡單的情況下,applicationContext.xml上下文不是必需的。它通常被用于包含webapp中所有servlet共享的bean。如果您只有一個servlet,那么沒有什么意義,除非你有特殊的用處。

回答二

簡單來說就是:

  • applicationContext.xml定義了在所有servlet之間共享的bean。如果您的應用程序有多個servlet,那么在applicationContext.xml中定義共有的資源那就很有用了。

  • spring-servlet.xml定義了只與該servlet相關的bean。這是dispatche servlet。因此,你的Spring MVCcontrollers 必須要在這個文件中定義。

  • 如果在web應用程序中只運行一個servlet,那么在spring-servlet.xml里面中定義所有的bean也是沒有問題的鴨。

文章翻譯自Stack Overflow:https://stackoverflow.com/questions/3652090/difference-between-applicationcontext-xml-and-spring-servlet-xml-in-spring-frame

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390914.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390914.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390914.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Alpha 沖刺 (5/10)

【Alpha go】Day 5! Part 0 簡要目錄 Part 1 項目燃盡圖Part 2 項目進展Part 3 站立式會議照片Part 4 Scrum 摘要Part 5 今日貢獻Part 1 項目燃盡圖 Part 2 項目進展 已分配任務進度博客檢索功能:根據標簽檢索流程圖 -> 實現 -> 測試近期比…

多維空間可視化_使用GeoPandas進行空間可視化

多維空間可視化Recently, I was working on a project where I was trying to build a model that could predict housing prices in King County, Washington — the area that surrounds Seattle. After looking at the features, I wanted a way to determine the houses’ …

蠻力寫算法_蠻力算法解釋

蠻力寫算法Brute Force Algorithms are exactly what they sound like – straightforward methods of solving a problem that rely on sheer computing power and trying every possibility rather than advanced techniques to improve efficiency.蠻力算法聽起來確實像是–…

NoClassDefFoundError和ClassNotFoundException之間有什么區別?是由什么導致的?

問題: NoClassDefFoundError和ClassNotFoundException之間有什么區別?是由什么導致的? NoClassDefFoundError和ClassNotFoundException之前的區別是什么? 是什么導致它們被拋出?這些問題我們要怎么樣解決? 當我在為了引入新的jar包而修改現有代碼…

關于Tensorflow安裝opencv和pygame

1.安裝opencv https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv C:\ProgramData\Anaconda3\Lib\site-packages>pip install opencv_python-3.3.1-cp36-cp36m-win_amd64.whlProcessing c:\programdata\anaconda3\lib\site-packages\opencv_python-3.3.1-cp36-cp36m-win_a…

內置的常用協議實現模版

SuperSocket內置的常用協議實現模版 中文(中國)Toggle Dropdownv1.6Toggle Dropdown關鍵字: TerminatorReceiveFilter, CountSpliterReceiveFilter, FixedSizeReceiveFilter, BeginEndMarkReceiveFilter, FixedHeaderReceiveFilter 閱讀了前面一篇文檔之…

機器學習 來源框架_機器學習的秘密來源:策展

機器學習 來源框架成功的機器學習/人工智能方法 (Methods for successful Machine learning / Artificial Intelligence) It’s widely stated that data is the new oil, and like oil, data needs the right refinement to evolve to be utilised perfectly. The power of ma…

linux gcc 示例_最好的Linux示例

linux gcc 示例Linux is a powerful operating system that powers most servers and most mobile devices. In this guide, we will show you examples of how to use some of its most powerful features. This involves using the Bash command line.Linux是功能強大的操作系…

帆軟報表和jeecg的進一步整合--ajax給后臺傳遞map類型的參數

下面是頁面代碼&#xff1a; <% page language"java" contentType"text/html; charsetUTF-8" pageEncoding"UTF-8"%> <%include file"/context/mytags.jsp"%> <% String deptIds (String)request.getAttribute("…

@Nullable 注解的用法

問題&#xff1a;Nullable 注解的用法 我看到java中的一些方法聲明為: void foo(Nullable Object obj){…}在這里Nullable是什么意思?這是不是意味著輸入可以為空? 沒有這個注解&#xff0c;輸入仍然可以是null&#xff0c;所以我猜這不是它的用法? 回答一 它清楚地說明…

WebLogic調用WebService提示Failed to localize、Failed to create WsdlDefinitionFeature

在本地Tomcat環境下調用WebService正常&#xff0c;但是部署到WebLogic環境中&#xff0c;則提示警告&#xff1a;[Failed to localize] MEX0008.PARSING_MDATA_FAILURE<SOAP_1_2 ......警告&#xff1a;[Failed to localize] MEX0008.PARSING_MDATA_FAILURE<SOAP_1_1 ..…

呼吁開放外網_服裝數據集:呼吁采取行動

呼吁開放外網Getting a dataset with images is not easy if you want to use it for a course or a book. Yes, there are many datasets with images, but few of them are suitable for commercial or educational use.如果您想將其用于課程或書籍&#xff0c;則獲取帶有圖像…

git push命令_Git Push命令解釋

git push命令The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository.git push命令允許您將提交(或推送 )從本地Git存儲庫中的本地分支發送到遠程存儲庫。 To be able to push to you…

在Java里面使用Pairs或者二元組

問題&#xff1a;在Java里面使用Pairs或者二元組 在Java里面&#xff0c;我的Hashtable要用到一個元組結構。在Java里面&#xff0c;我可以使用的什么數據結構呢&#xff1f; Hashtable<Long, Tuple<Set<Long>,Set<Long>>> table ...回答一 我不認…

github 搜索技巧

1、關鍵詞 指定開發語言 bitcoin language:javascript 2、關鍵詞 stars 數量 forks 數量 bitcoin stars:>100 forks:>50

React JS 組件間溝通的一些方法

剛入門React可能會因為React的單向數據流的特性而遇到組件間溝通的麻煩&#xff0c;這篇文章主要就說一說如何解決組件間溝通的問題。 1.組件間的關系 1.1 父子組件 ReactJS中數據的流動是單向的&#xff0c;父組件的數據可以通過設置子組件的props傳遞數據給子組件。如果想讓子…

數據可視化分析票房數據報告_票房收入分析和可視化

數據可視化分析票房數據報告Welcome back to my 100 Days of Data Science Challenge Journey. On day 4 and 5, I work on TMDB Box Office Prediction Dataset available on Kaggle.歡迎回到我的100天數據科學挑戰之旅。 在第4天和第5天&#xff0c;我將研究Kaggle上提供的TM…

sql limit子句_SQL子句解釋的位置:之間,之間,類似和其他示例

sql limit子句什么是SQL Where子句&#xff1f; (What is a SQL Where Clause?) WHERE子句(和/或IN &#xff0c; BETWEEN和LIKE ) (The WHERE Clause (and/or, IN , BETWEEN , and LIKE )) The WHERE clause is used to limit the number of rows returned.WHERE子句用…

在Java里面使用instanceof的性能影響

問題&#xff1a;在Java里面使用instanceof的性能影響 我正在寫一個應用程序&#xff0c;其中一種設計方案包含了instanceof操作的大量使用。雖然我知道面向對象設計通常試圖避免使用instanceof&#xff0c;但那是另一回事了&#xff0c;這個問題純粹只是討論與性能有關。我想…

Soot生成控制流圖

1.將soot.jar文件復制到工程bin目錄下&#xff1b;2.在cmd中執行如下命令java -cp soot-trunck.jar soot.tools.CFGViewer --soot-classpath .;"%JAVA_HOME%"\jre\lib\rt.jar com.wauoen.paper.classes.Activity其中&#xff0c;JAVA_HOME是jdk目錄&#xff1b;com.w…