Databases Reference
In-Depth Information
Configuring the transaction manager bean
We can configure the transaction manager bean by adding a transactionManager()
method to the ApplicationContext class and annotating this method with the
@Bean annotation. The implementation of this method is as follows:
1.
Create a new JpaTransactionManager object.
2.
Set a reference of the used entity manager factory.
3.
Return the created object.
The source code of the transaction manager bean configuration is given as follows:
@Bean
public JpaTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new
JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory().
getObject());
return transactionManager;
}
Loading the application context
configuration
The old way to load the application context configuration of our application is to use
the web application deployment descriptor file, which is more commonly known as
web.xml . However, because we are using the Spring Framework 3.1 in a Servlet 3.0
environment, we can create a web application configuration class by implementing
the WebApplicationInitializer interface. This ensures that Spring Framework
automatically detects our configuration class when a servlet container is started.
We will use our web application configuration class to:
1. Load our application context configuration class.
2. Configure the dispatcher servlet .
3.
Create the context loader listener and add it to our servlet context .
The source code of our configuration class is given as follows:
public class DataJPAExampleInitializer implements
WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws
ServletException {
 
Search WWH ::




Custom Search