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);
您应该能够使用以下内容获取ServletContext:
messageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT);
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.