lishman levelup
«previous  next»

Getting Started
Form Processing
IoC Container
Hibernate ORM

Spring IoC Container Configuration

We can improve the overall structure of our application by creating a separate configuration file for each tier. So far, we have world-servlet.xml but, as the name suggests, this should only provide configuration details for the presentation layer.

Business Logic Configuration

A second file called applicationContext.xml is created in the WEB-INF directory, with the following contents:

  <context:component-scan base-package=""/>

The configuration is very simple because all we require of Spring is to locate our service components and make them available for autowiring.


We tell Spring where to find the new configuration file by adding the following entries to web.xml.




ContextLoaderListener loads the configuration file(s) specified in the contextConfigLocation context parameter into Spring's root context. DispatcherServlet then loads the servlet configuration into a separate context, with the root context as its parent. This means that the settings in the servlet context can refer to, and even override, the settings in the root context.

Tip - we introduce a configuration file for the data layer in Hibernate Object Relational Mapping with Spring MVC.