是否可以仅使用dispatcher-servlet.xml来运行spring-orm程序?不使用ContextLoaderListener和applicationcontext.xml?如果是,那么是如何实现的?
其次,为什么有必要在web.xml中注册dispatcher-servlet.xml或applicationcontext.xml?因为当这些文件没有在web.xml中注册时,所有的setter注入(在dispatcher-servlet.xml或applicationcontext.xml中指定)都会在服务器启动时发生,这意味着这些web.xml文件不需要在web.xml中注册就可以加载。
发布于 2011-12-11 03:09:26
是否可以仅使用dispatcher-servlet.xml来运行spring-orm程序。不使用ContextLoaderListener和applicationcontext.xml?
是的,那很好。
如果是,那么是如何实现的?
你只要做就行了。把你需要的一切都放到dispatcher-servlet.xml里,它会自己运行的。虽然常见的做法是将DAO相关的内容放在applicationContext.xml中,将MVC放在dispatcher-servlet.xml中,但这绝不是必需的。如果你愿意,它可以全部放在一个文件中。
其次,为什么有必要在web.xml中注册dispatcher-servlet.xml或applicationcontext.xml?因为当这些文件没有在web.xml中注册时,所有的设置器注入(在dispatcher-servlet.xml或applicationcontext.xml中指定)都会在服务器启动时发生,这意味着这些web.xml文件不需要注册就可以加载。
因为如果您不在web.xml中指定它们,Spring将使用其缺省值并查找它们。默认情况下,DispatcherServlet将查找<servlet-name>-servlet.xml,ContextLoaderListener将查找/WEB-INF/applicationContext.xml。如果愿意,您可以在web.xml中覆盖它。
https://stackoverflow.com/questions/8458955
复制相似问题