Example & Tutorial understanding programming in easy ways.

What is the difference between the @ComponentScan and @EnableAutoConfiguration annotations in Spring Boot?

@EnableAutoConfiguration annotation tells Spring Boot to "guess" how you will want to configure Spring, based on the jar dependencies that you have added.
For example, If HSQLDB is on your classpath, and you have not manually configured any database connection beans, then Spring will auto-configure an in-memory database.

@ComponentScan tells Spring to look for other components, configurations, and services in the specified package.
Spring is able to auto scan, detect and register your beans or components from per-defined project package.

If no package is specified current class package is taken as the root package. There are some annotations which make beans auto-detectable like @Repository , @Service, @Controller, @Configuration, @Component

Provides scope for spring component scan, it simply goes though the provided base package and picks up dependencies required by @Bean or @Autowired etc,

Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!