Reputation: 466
Currently, we have to add rollbackFor=Exception.class
for 90% of the methods in our application that use @Transactional
annotation. I was wondering if there is a way to set the default for rollbackFor
to Exception.class
somewhere so that we don't have to explicitly specify it every time.
Upvotes: 1
Views: 1101
Reputation: 21883
Since it is an annotation, the standard is writing your own custom annotation and replacing it with @Transactional(rollbackFor = Exception.class)
. If you annotate with the following annotation you don't need to specify rollbackFor
in everywhere because it will be implied.
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(rollbackFor = Exception.class)
@Documented
public @interface CustomTransactional {
}
Upvotes: 5