Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Spring to print out the bean definitions it is picking up via component scanning?

I have a spring app that is configured for Component Scanning, is there a flag or option that I can turn on that would cause spring to print out the fully qualified names of the classes that the spring framework scanner picks up?

like image 272
ams Avatar asked Dec 17 '11 07:12

ams


People also ask

How do I enable component scans in Spring?

Using @ComponentScan in a Spring Application. With Spring, we use the @ComponentScan annotation along with the @Configuration annotation to specify the packages that we want to be scanned. @ComponentScan without arguments tells Spring to scan the current package and all of its sub-packages.

How does Spring scan for beans?

For example , it has an attribute called scanBasePackages which tells Spring to scan the beans (A class that is annotated with @Component or its sterotypes such as @Service , @Repository , @Controller etc. ) from certain packages and its sub-packages only.

How do you enable scanning for various annotations?

In order to activate them, we can add either <context:annotation-config> or <context:component-scan> on top of our XML file. In this section, we'll see how <context:annotation-config> and <context:component-scan> differ from each other in terms of their ways of activating annotations.

How do I scan beans in Spring boot?

Spring provides a mechanism to identify Spring bean candidates explicitly through the @ComponentScan annotation. If the application is a Spring Boot application, then all the packages under the package containing the Spring Boot application class will be covered by an implicit component scan.


1 Answers

You can print this by configuring logging category (assuming you are using log4j), set org.springframework.context.annotation at debug level.

Check org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(String).

You can see the class is logging name of the classes at debug level. Verified in Spring 3.0.5 version.

like image 167
Adisesha Avatar answered Oct 17 '22 01:10

Adisesha