[英]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.