在 Spring MVC 中,应用程序级 bean 应该放在哪里?进入 root-context.xml
或 servlet-context.xml
?
最佳答案
在 root-context.xml
中声明的 Bean(服务)对于 servlet-context.xml
中的 Bean( Controller ),但反之则不然。因此,可以存在从 Controller 到服务的依赖关系,但 Spring 禁止反向依赖。
也就是说,将独立于 MVC 的代码(服务、DAO 等)放在主上下文中,并将仅 Web 的内容放在 servlet 上下文中。
关于spring - Spring MVC 中应用程序级别的 Bean 应该放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9168354/