Skip to content

Instantly share code, notes, and snippets.

@snicoll
Last active August 29, 2015 14:15
Show Gist options
  • Save snicoll/8a517c060ee072889e63 to your computer and use it in GitHub Desktop.
Save snicoll/8a517c060ee072889e63 to your computer and use it in GitHub Desktop.
Core interceptors overhaul

Core interceptors overhaul

The Spring Framework has evolved over the years, introducing interceptors for various features such as caching and asynchronous method execution. The purpose of this document is to describe those interceptors and see what we can harmonize. It’s also a chance to look at a way to mutualize some processing and hopefully improve the processing time if need to be.

Interceptors

This summarizes the core interceptors that are defined by the framework

Table 1. Core interceptors
Annotation Enable Annotation Interceptor Description

@Async

@EnableAsync

AsyncAnnotationBeanPostProcessor

Create a proxy to delegate the processing to a separate thread

@Cache*

@EnableCaching

CacheInterceptor

Pointcut-based interceptor, cache result of method invocation

@EventListener

automatic

EventListenerMethodProcessor

Register an ApplicationListener for each annotated method

@JmsListener

@EnableJms

JmsListenerAnnotationBeanPostProcessor

Create a JMS listener container on the fly for the annotated method

@Scheduled

@EnableScheduling

ScheduledAnnotationBeanPostProcessor

Invoke a given method at the configured rate

@Transactional

@EnableTransactionManagement

TransactionInterceptor

Pointcut-based interceptor, manage transaction boundaries

@Validated

none

MethodValidationPostProcessor

Validate method arguments and return types

Features

The table belows summarizes the features of each interceptor. This should give a proper overview of what we could share for reuse

Table 2. Features
Feature Service Qualifier Method-based inspection

@Async

yes

no

@Cache*

n/a

no

@EventListener

n/a

yes

@JmsListener

yes

yes

@Scheduled

desirable (?)

yes

@Transactional

yes

no

@Validated

desirable

no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment