0

When I try to make a call to my spring web client, I get the error:

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: 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 "true" to servlet and filter declarations in web.xml.

I do not have access / rather not mess with the web.xml file. My spring controller is as follows:

@Controller
@RequestMapping("/test/test")
public class MyController
{
     //Using DeferedResult and Http get / post
}

Things i tried: putting @Async above class and above the methods for get/post. Also tried putting @EnableAsync above the class. How do I enable async support in the java code without doing it in the web.xml? Could not find much help online

4
  • Show your web.xml file Commented Jul 1, 2015 at 0:20
  • I don't have access to the web.xml file as I said. I need to do it the java way Commented Jul 1, 2015 at 0:25
  • Yeah but your web.xml might be improperly configured. It's not just about doing it "the java way". Commented Jul 1, 2015 at 0:26
  • Are you using Java based configuration for your servlet? Commented Jul 1, 2015 at 0:31

1 Answer 1

2

If you use java style application context instead of xml, below configuration should work

@Configuration
@EnableAutoConfiguration
@EnableAsync
@ComponentScan("your.package")
public class AppConfig extends SpringBootServletInitializer implements AsyncConfigurer {

    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(20);
        executor.setMaxPoolSize(100);
        executor.setQueueCapacity(200);
        executor.initialize();
        return executor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new MyAsyncExceptionHandler();
    }
}

Also here is example for the asyncExceptionHandler

public class MyAsyncExceptionHandler implements AsyncUncaughtExceptionHandler {

    static Logger log = Logger.getLogger(MyAsyncExceptionHandler.class.getName());

    @Override
    public void handleUncaughtException(Throwable throwable, Method method, Object... obj) {
        log.error("Exception message - " + throwable.getMessage());
        log.error("Method name - " + method.getName());
        for (Object param : obj) {
            log.error("Parameter value - " + param);
        }

    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.