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. All the classes we have defined until now are present in this package as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset