user7361363
user7361363

Reputation:

How to check what annotations are included by other annotation

We know that there are annotations that include automatically other annotations.
Can you tell me how to check if @EnableAutoConfiguration include (it means adds under hood) @EnableTransactionManagement

Thanks in advance, Regards

Upvotes: 0

Views: 368

Answers (3)

Ruchi Saini
Ruchi Saini

Reputation: 301

There is spring.factories in META-INF of spring-boot-autoconfigure-{whatever-is-ur-bootversion}.jar

Open spring.factories and have a look EnableAutoConfiguaration annotation is equal to many comma separated configuration files. And specific configuration files are automatically loaded based on your starters.

You can open these files and evaluate.

Upvotes: 0

RustyTheBoyRobot
RustyTheBoyRobot

Reputation: 5955

Spring Boot can give you a list of all the beans that it created along with some information about why it chose to include/exclude them. Just set the property debug=true and watch the logged output on startup. This is demonstrated in this video: https://www.youtube.com/watch?v=Sw7I70vjN0E&list=WL&t=615

I don't know if it will specifically print out the @Enable... annotations, but those annotations generally just provide an @Import annotation to some configuration. Looking the source of @EnableTransactionManagement, I see this:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(TransactionManagementConfigurationSelector.class)
public @interface EnableTransactionManagement {

If you use the debug property, Spring will definitely print out whether or not it created a TransactionManagementConfigurationSelector bean, which should tell you whether or not @EnableTransactionManagement was used in your application.

Upvotes: 0

Barath
Barath

Reputation: 5283

I think you can do like this :

 ClassPathScanningCandidateComponentProvider scanner =
                    new ClassPathScanningCandidateComponentProvider(false);
            scanner.addIncludeFilter(new AnnotationTypeFilter(EnableAutoConfiguration.class));
                for(BeanDefinition bean:scanner.findCandidateComponents("PACKAGES TO SCAN")){

                Class<?> aClass=Class.forName(bean.getBeanClassName()); 
`// you can also use aClass.getAnnotatedInterfaces() to find the other` annotations     
                if(aClass != null && aClass.isAnnotationPresent(EnableTransactionManagement.class)){
                    System.out.println(" Found "+aClass.getName());                         
                }       
            }

Upvotes: 0

Related Questions