引言
记录一下MyBatis中 @Intercepts、@Signature 是如何生效的。
1.插件初始化过程
1.1.配置一个xml
<configuration>
<plugins>
<plugin interceptor="org.apache.ibatis.plugin.PluginTest$SwitchCatalogInterceptor" />
</plugins>
</configuration>```
1.2.插件被装载
1.3.四种类型的插件被调用
Invocation 这个类被作为org.apache.ibatis.plugin.Interceptor#intercept 的入参;
在构造器中存在判断如下
private static final List<Class<?>> targetClasses = Arrays.asList(Executor.class, ParameterHandler.class,
ResultSetHandler.class, StatementHandler.class);
public Invocation(Object target, Method method, Object[] args) {
if (!targetClasses.contains(method.getDeclaringClass())) {
throw new IllegalArgumentException("Method '" + method + "' is not supported as a plugin target.");
}
this.target = target;
this.method = method;
this.args = args;
}
四种类型的插件被加载,并编入逻辑