I have a custom method annotation (@EventListener) that I use in a method inside a class that has the @Transactional annotation.
Below is a sample of the class
@Component
@Transactional
public class someClass {
@EventListener
public void someMethod() {
}
}
The class is in a package include in the context files component scan. In another class which implements ApplicationContextAware, I check the methods of the classes if they have my @EventListener annotation. For some strange reason, when @Transactional is present in the class, my custom annotation is lost.
This is how I check for the method annotations:
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println("SCANNING :::::: " + beanName);
for (Method method : bean.getClass().getMethods()) {
for(Annotation a : method.getAnnotations()) {
System.out.println("\t>>>>> " + a.toString());
}
...
Is there a way to use @Transactional without it messing up with other method annotations in the class it annotates?
Edit: I found this after I posted Spring - @Transactional - What happens in background? - seems some sort of a proxy is created it would appear that this causes my annotations to "disappear". Is there a way to get a reference to the original class?