java - 来自 Spring 应用程序上下文的 Servlet 上下文属性
问题描述
我正在尝试摆脱真正旧的 servlet 并在它们的位置添加临时服务。
这是否可以从应用程序上下文中获取与我之前从 servlet 上下文中获取的数据相同的数据?
更具体地说,我试图servletContext.getAttribute("org.directwebremoting.ContainerList")
从应用程序上下文中获取属性,但ApplicationContext
没有getAttribute
方法。
解决方案
Spring 使用Servlet
s 作为支持技术。因此,您只需要获取ServletContext
与之相关的内容Servlet
并检索属性。
对于根上下文,使用WebApplicationContext
. 该接口getServletContext()
向通用 ApplicationContext 接口添加了一个方法。
Object attribute = webApplicationContext
.getServletContext()
.getAttribute("org.directwebremoting.ContainerList");
推荐阅读
- javascript - Puppeteer:遍历 URL 并等待按顺序打印?
- c# - 数据网格内的组合框不包含可见的值
- reactjs - 如何在 Victory Pie 中指定数据对象内的色阶
- c# - C# TcpListener 不监听
- node.js - 如何修复我的 npm start 脚本?
- vba - VBA Dec2Hex 转换无法正常工作
- angular - 如果我们手动为 Firebase 数据库生成文档 ID,它会影响搜索操作吗?
- php - TCPDF 中的内容不破坏属性 (nobr) 在第二个标签中无法正常工作
- c++ - char p[0] 是表示自动分配的缓冲区还是安全指针?
- python - python的高级循环问题