簡體   English   中英

來自 Spring 應用程序上下文的 Servlet 上下文屬性

[英]Servlet context attribute from Spring application context

我正在嘗試擺脫非常舊的 servlets 並添加他們的臨時服務。

這是否可以從應用程序上下文中獲取與我之前從 servlet 上下文中獲取的數據相同的數據?

更具體地說,我試圖從應用程序上下文中獲取屬性servletContext.getAttribute("org.directwebremoting.ContainerList") ,但ApplicationContext沒有getAttribute方法。

Spring 使用Servlet作為后盾技術。 因此,您只需要獲取與該Servlet相關的ServletContext並檢索屬性即可。

對於根上下文,使用WebApplicationContext 該接口向通用 ApplicationContext 接口添加了一個getServletContext()方法。

Object attribute = webApplicationContext
                .getServletContext()
                .getAttribute("org.directwebremoting.ContainerList");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM