2013-04-09 2 views
0

Как я могу получить объект ServletContext из MessageContext, поставляемого в перехватчике? TODO ниже - это ServletContext.Получить ServletContext из MessageContext в перехватчике

@Override 
public boolean handleRequest(MessageContext messageContext, Object endpoint) 
     throws Exception { 

    WebApplicationContext applicationContext = 
      WebApplicationContextUtils.getWebApplicationContext(TODO); 
      TestIdentitiesService service = applicationContext.getBean(TestIdentitiesService.class); 

ответ

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); 
+0

Это freaking работало спасибо. –

1

Вы должны быть в состоянии получить ServletContext со следующим:

messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT); 
+0

Свойства объекта на MessageContext пуст, так что не работает. –

Смежные вопросы