O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The @ComponentScan annotation

Spring needs to know which packages contain Spring beans, otherwise, you would have to register each bean individually. That's what @ComponentScan is used for. In Spring, component scanning is not enabled by default. We need to enable it with the @ComponentScan annotation. This annotation is used with the @Configuration annotation to allow Spring to know the packages to scan for annotated components and to create beans from them. Let's look at the following simple example of @ComponentScan:

@Configuration@ComponentScan(basePackages="com.packt.springhighperformance.ch2.bankingapp.model")public class AppConfig {}

In the @ComponentScan annotation, if the basePackages attribute is not defined, then scanning will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required