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:
Load our application context configuration class.
Configure the dispatcher servlet.
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 { //Loading...