The moose likes Spring and the fly likes Multiple contexts Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "Multiple contexts" Watch "Multiple contexts" New topic
Author

Multiple contexts

james frain
Ranch Hand

Joined: Apr 06, 2011
Posts: 34
I have an MVC enabled application that has a single dispactcher servlet with it's springapp-servlet.xml configuration file.
I am trying to get my head around the syntax I hear people use. For instance does this single servlet along with it's xml cfg file amount to what people call a context? I assume I can have more than one dispatcher servlet with an accompanying cfg file so in that case is that an application with multiple contexts?
Basically I'm trying to understand web applications from a high level before really getting into the nuts and bolts of the business logic and navigation, requests, responses etc
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

james frain wrote:I have an MVC enabled application that has a single dispactcher servlet with it's springapp-servlet.xml configuration file.
I am trying to get my head around the syntax I hear people use. For instance does this single servlet along with it's xml cfg file amount to what people call a context? I assume I can have more than one dispatcher servlet with an accompanying cfg file so in that case is that an application with multiple contexts?
Basically I'm trying to understand web applications from a high level before really getting into the nuts and bolts of the business logic and navigation, requests, responses etc


Yes, you can have multiple contexts. And in the case of Spring MVC, you want two contexts. One for just the web layer beans and one for the middle tier services/repositories. The middle tier one becomes the Parent context of the Web Layer's child context. Which means the child context can see any beans in the parent context. but the parent context cannot see the child context. You want to inject Services into your Controllers, but you definitely never want to inject a Controller into a Service. Call down the stack not up.

Hope that helps

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Multiple contexts
 
Threads others viewed
doubt about constraints of WEB-INF folder
Upgrading to Tomcat6 problems
Sessions from multiple apps on single server...
Multiple contexts pointing to the same application
Top 10 Servlet/JSP misconceptions.
Two Laptop Bag

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture