如何从拦截器中提供的 MessageContext 获取 ServletContext 对象? 下面的 TODO 假设是一个 ServletContext。
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint)
throws Exception {
WebApplicationContext applicationContext =
WebApplicationContextUtils.getWebApplicationContext(TODO);
TestIdentitiesService service = applicationContext.getBean(TestIdentitiesService.class);
最佳答案
您可以尝试以下操作:
@Autowired
private ServletContext context;
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint)
throws Exception {
WebApplicationContext applicationContext =
WebApplicationContextUtils.getWebApplicationContext(context);
TestIdentitiesService service =
applicationContext.getBean(TestIdentitiesService.class);
关于java - 拦截器中从MessageContext获取ServletContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15914567/