Skip to content

Commit 727e9d7

Browse files
Fixes 71. Transactional annotation does not intercept synthetic methods.
1 parent 618327a commit 727e9d7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/org/mybatis/guice/AbstractMyBatisModule.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public boolean matches(Method method) {
4242
return method.getDeclaringClass() == Object.class;
4343
}
4444
};
45+
protected static final AbstractMatcher<Method> SYNTHETIC = new AbstractMatcher<Method>() {
46+
@Override
47+
public boolean matches(Method method) {
48+
return method.isSynthetic();
49+
}
50+
};
4551

4652
private ClassLoader resourcesClassLoader = getDefaultClassLoader();
4753

@@ -77,11 +83,11 @@ protected void bindTransactionInterceptors() {
7783
// transactional interceptor
7884
TransactionalMethodInterceptor interceptor = new TransactionalMethodInterceptor();
7985
requestInjection(interceptor);
80-
bindInterceptor(any(), not(DECLARED_BY_OBJECT).and(annotatedWith(Transactional.class)), interceptor);
86+
bindInterceptor(any(), not(SYNTHETIC).and(not(DECLARED_BY_OBJECT)).and(annotatedWith(Transactional.class)), interceptor);
8187
// Intercept classes annotated with Transactional, but avoid "double"
8288
// interception when a mathod is also annotated inside an annotated
8389
// class.
84-
bindInterceptor(annotatedWith(Transactional.class), not(DECLARED_BY_OBJECT).and(not(annotatedWith(Transactional.class))), interceptor);
90+
bindInterceptor(annotatedWith(Transactional.class), not(SYNTHETIC).and(not(DECLARED_BY_OBJECT)).and(not(annotatedWith(Transactional.class))), interceptor);
8591
}
8692

8793
/**

0 commit comments

Comments
 (0)