This is done in Java code using the Servlet API or by adding async-supported true async-supported

There was an unexpected error (type=Internal Server Error, status=500).

Async support must be enabled on a servlet and for all filters involved in async request processing. This is done in Java code using the Servlet API or by adding "<async-supported>true</async-supported>" to servlet and filter declarations in web.xml.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/>
    </parent>

最近刚刚接触WebFlux“响应式”接口,但是一直报这个错误,提示我在web.xml开启异步支持,但是我是SpringBoot项目= =,于是开始网上查找。

网上普遍给出的答案是 :

  @Bean
    public ServletRegistrationBean dispatcherServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(
                new DispatcherServlet(), "/");
        registration.setAsyncSupported(true);
        return registration;
    }

但是我配置了,却有了新错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method dispatcherServletRegistration in org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration required a bean of type 'org.springframework.web.servlet.DispatcherServlet' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.web.servlet.DispatcherServlet' in your configuration.

这里不是很清楚为什么没有注入,但是解决方法就是把DispatcherServlet注入进去即可解决。

以下是我整个class

@Configuration
public class OnlyConfiguration{
//    @Autowired
//    private DispatcherServlet dispatcherServlet;
    /**
     * 开启异步支持
     * @return
     */
    @Bean
    public ServletRegistrationBean dispatcherServletBean() {
        ServletRegistrationBean registration = new ServletRegistrationBean(
                this.dispatcherServlet(), "/");
        registration.setAsyncSupported(true);

        return registration;
    }
    @Bean
    DispatcherServlet dispatcherServlet(){
        return new DispatcherServlet();
    }

}

问题还是没有解决

后来发现:

在Apllication.class 启动文件中,存在

@ServletComponentScan(xxx.xxx)

注解

每一个filter相当于是一个Servlet,所以在xxx.xxx这个扫描路径下所有的Filter也需要加

 asyncSupported = true

(如果访问的接口也需要异步支持)

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值