How to handle HTTP OPTIONS with Spring MVC?

前端 未结 5 1288
鱼传尺愫
鱼传尺愫 2020-11-29 07:28

I\'d like to intercept the OPTIONS request with my controller using Spring MVC, but it is catched by the DispatcherServlet. How can I manage that?

5条回答
  •  孤独总比滥情好
    2020-11-29 07:54

    For Spring without web.xml file, and based on Paul Adamson answer, I just set the parameter dispatchOptionsRequest to true into the dispatcher, to process the Options method calls.

    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new        DispatcherServlet(applicationContext));
    
    dispatcher.setInitParameter("dispatchOptionsRequest", "true");                
    
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/*");
    

提交回复
热议问题