Databases Reference
In-Depth Information
Creating the application context configuration
class
We can create the application context configuration class by following these steps:
1. Create an application context configuration skeleton that contains the general
configuration of the application.
2. Configure the data source bean.
3. Configure the entity manager factory bean.
4. Configure the transaction manager bean.
Creating the application context configuration
skeleton
The steps that are needed to create a skeleton configuration class of the Spring
application context are described in the following steps:
1. The @Configuration annotation identifies the class as an application context
configuration class.
2. The component scanning directives are configured with the @ComponentScan
annotation. In our example, the Spring IoC container is configured to scan
the packages containing our controller and service classes.
3. The @EnableJpaRepositories annotation is used to enable Spring Data JPA
and configure the base package of our repositories.
4. The @EnableTransactionManagement annotation enables the
annotation-driven transaction management of Spring Framework.
5. The @EnableWebMcv annotation imports the default configuration of
Spring MVC.
6. The properties file containing the values of the configuration parameters
is imported by using the @PropertySource annotation. We can access
the property values stored in this file by using the implementation of the
Environment interface that is injected by the Spring IoC container.
The source code of our application context configuration skeleton is given as follows:
@Configuration
@ComponentScan(basePackages = {
"com.packtpub.springdata.jpa.controller",
"com.packtpub.springdata.jpa.service"
})
 
Search WWH ::




Custom Search