2

I have to develop a full fledged project. by full fledged i mean need to insert, update delete values in a database, Performing operations on values. Its like i have set of model classes for every object. Employee, products etc. its a web application developed using Spring MVC. I know when a user enters a data in a form , the request goes to dispatcher servlet from there to a particular handler(Controller) and then to view. But i don't know what application Context or web Application Context does ? its like is it necessary to have that xml file. ? What all it contains. thanks ...

4

1 回答 1

3

你的假设是对的。你不知道的是它DispatcherServlet有自己的上下文,定义在*-servlet.xml. 此上下文通常是主应用程序上下文的子级,通常在applicationContext.xml. Child 可以访问在父上下文中定义的所有 bean,但反之则不行。

从理论上讲,您可以只使用一个DispatcherServlet上下文并在那里拥有所有 bean(DAO、服务、事务划分)。但在较大的项目中,这是一种糟糕的做法。还有两个上下文允许您在业务逻辑和 Web 层之间划清界限。

实际含义 - 如果您有两个DispatcherServlets,如果它们没有共同的父上下文,则无法在它们之间共享 bean。

于 2012-04-03T06:58:45.190 回答