Java configuration for the application context

The following example shows how to create a simple Java context configuration:

    @Configuration     class SpringContext {     }

The key is the @Configuration annotation. This is what defines this as a Spring configuration.

One question remains; how does Spring IoC container know where to search for beans?

We need to tell the Spring IoC container the packages to search for by defining a component scan. Let's add a component scan to our earlier Java configuration definition:

    @Configuration     @ComponentScan(basePackages = { "com.mastering.spring" })      class SpringContext {      }

We have defined a component scan for the com.mastering.spring package. It shows how all the classes we discussed until now are organized. ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.