【问题标题】:Servlet context attribute from Spring application context来自 Spring 应用程序上下文的 Servlet 上下文属性
【发布时间】:2020-09-25 02:47:09
【问题描述】:

我正在尝试摆脱非常旧的 servlet 并添加临时服务。

这是否可以从应用程序上下文中获取与我之前从 servlet 上下文中获取的数据相同的数据?

更具体地说,我正在尝试从应用程序上下文中获取属性 servletContext.getAttribute("org.directwebremoting.ContainerList"),但 ApplicationContext 没有 getAttribute 方法。

【问题讨论】:

    标签: java spring spring-mvc servlets applicationcontext


    【解决方案1】:

    Spring 使用Servlets 作为支持技术。因此,您只需要获取与该Servlet 相关的ServletContext 并检索属性即可。

    对于根上下文,使用WebApplicationContext。该接口向通用 ApplicationContext 接口添加了一个getServletContext() 方法。

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

    【讨论】:

      猜你喜欢
      • 2019-08-13
      • 1970-01-01
      • 2012-01-06
      • 2015-07-10
      • 1970-01-01
      • 2020-06-08
      • 2015-02-19
      • 1970-01-01
      • 2010-09-09
      相关资源
      最近更新 更多