I usually do it using the following JUnit Test Case:
/**
* Test if all the @Services bean are annotated with the @Transactional
* annotation.
*/
@Test
public void testServicesTransactionalAnnotations(){
String[] beansNames = applicationContext.getBeanDefinitionNames();
StringBuilder sb = new StringBuilder();
for(String beanName : beansNames){
Service serviceAnnotation = applicationContext.findAnnotationOnBean(beanName, Service.class);
if(serviceAnnotation != null && applicationContext.findAnnotationOnBean(beanName,
Transactional.class) != null){
Transactional transactional = applicationContext.findAnnotationOnBean(beanName,
Transactional.class);
if(!transactional.propagation().equals(Propagation.MANDATORY)){
sb.append("Missing @Transactional Annotation in bean:").append(beanName).append("\n");
}
}
Assert.assertTrue(sb.toString(), StringUtils.isBlank(sb.toString()));
}
It checks that all the beans annotated with @Service are marked as Transactional too. I use the String Builder to be able to know which beans are missing the annotation.