Reputation: 24325
How can I get an object of ServletContext from the MessageContext supplied in an interceptor? The TODO below is suppose to be a ServletContext.
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint)
throws Exception {
WebApplicationContext applicationContext =
WebApplicationContextUtils.getWebApplicationContext(TODO);
TestIdentitiesService service = applicationContext.getBean(TestIdentitiesService.class);
Upvotes: 0
Views: 1380
Reputation: 3091
You can try the following:
@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);
Upvotes: 2
Reputation: 11643
You should be able to get a ServletContext with the following:
messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
Upvotes: 1