Skip to content

Commit f8691bb

Browse files
committed
fixed @transactional discovery
1 parent f979556 commit f8691bb

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

core/src/main/java/org/sterl/spring/persistent_tasks/task/util/ReflectionUtil.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ public abstract class ReflectionUtil {
1212

1313
public static <A extends Annotation> A getAnnotation(PersistentTask<? extends Serializable> inTask, Class<A> searchFor) {
1414
var task = AopProxyUtils.ultimateTargetClass(inTask);
15-
A result = AnnotationUtils.findAnnotation(task, searchFor);
16-
if (result != null) return result;
17-
1815
var targetMethod = ReflectionUtils.findMethod(task, "accept", Serializable.class);
19-
if (targetMethod == null) return null;
16+
17+
A result = null;
18+
// check the method first
19+
if (targetMethod != null) result = AnnotationUtils.findAnnotation(targetMethod, searchFor);
20+
// check the class if no method annotation was found
21+
if (result == null) result = AnnotationUtils.findAnnotation(task, searchFor);
2022

21-
result = AnnotationUtils.findAnnotation(targetMethod, searchFor);
2223
return result;
2324
}
2425
}

core/src/test/java/org/sterl/spring/persistent_tasks/task/TaskTransactionTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public void accept(String name) {
3636
personRepository.save(new PersonBE(name));
3737
}
3838
}
39+
3940
@Component("transactionalMethod")
41+
@Transactional(timeout = 76, propagation = Propagation.REQUIRED, isolation = Isolation.REPEATABLE_READ)
4042
@RequiredArgsConstructor
4143
static class TransactionalMethod implements PersistentTask<String> {
4244
private final PersonRepository personRepository;
@@ -96,7 +98,7 @@ void testFindTransactionAnnotation() {
9698
assertThat(a).isNotNull();
9799
assertThat(a.timeout()).isEqualTo(7);
98100
}
99-
101+
100102
@Test
101103
void testGetTransactionTemplate() {
102104
var a = subject.getTransactionTemplate(transactionalClass);

0 commit comments

Comments
 (0)