Understanding the web application context configuration

The web application context configuration file (WebApplicationContextConfig.java) is nothing but a simple Java-based Spring bean configuration class. Spring will create beans (objects) for every bean definition mentioned in this class during the boot up of our application. If you open this web application context configuration file, you will find the following annotations on top of the class definition:

  • @Configuration: This indicates that a class declares one or more @Bean methods
  • @EnableWebMvc: Adding this annotation to an @Configuration class imports some special Spring MVC configuration
  • @ComponentScan: This specifies the base packages to scan for annotated components (beans)

The first annotation ...

Get Spring: Developing Java Applications for the Enterprise now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.