从拦截器中的MessageContext获取ServletContext

时间:2013-04-09 23:52:40

标签: java spring spring-ws

如何从拦截器中提供的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);

2 个答案:

答案 0 :(得分:1)

您应该能够使用以下内容获取ServletContext:

messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);

答案 1 :(得分:1)

您可以尝试以下操作:

@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);