Description
If there are multiple interceptors intercepting the same method, the same number of dynamic proxy classes will be created. However, the dynamic proxy has certain performance loss. I hope that it can be optimized to avoid the creation of multiple dynamic proxy classes.
example:
@Intercepts({
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
})
public class MyInterceptor implements Interceptor {
private static final Logger logger = LoggerFactory.getLogger(MyInterceptor.class);
private Properties properties;
@Override
public void setProperties(Properties properties) {
this.properties = properties;
}
@Override
public Object intercept(Invocation invocation) throws Throwable {
logger.info("invoke");
return invocation.proceed();
}
}
@Intercepts({
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
})
public class MyInterceptor2 implements Interceptor {
}
This will cause two dynamic proxy classes to be created !!!
At present, Mybatis supports four types of interface interception
ParameterHandler
, ResultSetHandler
, StatementHandler
, Executor
Proposal 1: change to responsibility chain mode,developers can provide specific implementation classes of these interfaces to intercept corresponding methods
Proposal 2: Only a proxy class can be used to intercept interface methods,The advantage of this approach is that it does not change the existing interceptor implementation logic