gpt4 book ai didi

java - 拦截器中从MessageContext获取ServletContext

转载 作者:行者123 更新时间:2023-12-02 07:07:35 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com