Skip to content

Doc: @Async in an Interceptor postHandle() doesn't work [SPR-16092] #20641

Closed
@spring-projects-issues

Description

@spring-projects-issues

Pawan Kumar opened SPR-16092 and commented

If you use a @Async("yourExecutorBeanName") in a method called by an interceptor's postHandle method (whether same class or different class), the Async nature doesn't come into picture, nor does Spring complain for a wrong bean type if doesn't exist by name of "yourExecutorBeanName".

public class EventHandlerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView) throws Exception {
      //some custom logic
      publishSomeEvent(someRequestObj);
    }

    @Async("eventHandlerExecutor")
    public void publishSomeEvent(Request someRequestObj) {
        logger.info("Inside EventHandlerInterceptor - trying for Async.. doesn't work");
        //do something Async.
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        					http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">

    <!--Default Executor and Schedulers to pick-->
    <task:annotation-driven executor="eventHandlerExecutor"/>
    <task:executor id="eventHandlerExecutor" pool-size="30-40" queue-capacity="40"/><!--Not working inside Interceptor-->

</beans>

Backported to: 4.3.13

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions