Spring – multiple contexts

Spring MVC normally contains several xml files for configuration:

  • web.xml – required for java web aplications (used to configure following two)
    • applicatonContext.xml  – defines the root context (shared by all)
      • location & name is specified by the contextConfigLocation property in web.xml
    • dispatcher-servlet.xml or spring-servlet.xml or any other name – defines the mvc context
      • location & name specified by the DispatcherServlet property
      • inherits from root context
      • Used to declare MVC components, ex: ViewHandlerResolvers, @Controller scanning, <resource> mappings, etc
      • usual names:

Interesting post on how to go about loading Multiple Spring contexts: http://blog.codehangover.com/load-multiple-contexts-into-spring/

Explains the difference between loading through:

  • web.xml (contextConfigLocation)  vs.  using <import> statements

Dicussions on StackOverflow regarding best practices.

Tagged with: , , ,
Posted in Spring, Spring MVC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: