Java 我的spring程序是否可以使用dispatcher-servlet.xml运行,而不使用ContextLoaderListener和applicationcontext.xml?
是否可以仅使用Java 我的spring程序是否可以使用dispatcher-servlet.xml运行,而不使用ContextLoaderListener和applicationcontext.xml?,java,spring,spring-mvc,Java,Spring,Spring Mvc,是否可以仅使用dispatcherservlet.xml运行spring orm程序。不使用ContextLoaderListener和applicationcontext.xml?如果是,那怎么办 其次,为什么需要在web.xml中注册dispatcherservlet.xml或applicationcontext.xml?因为当这些文件未在web.xml中注册时,所有setter注入(在dispatcher servlet.xml或applicationcontext.xml中指定)都发生在
dispatcherservlet.xml
运行spring orm程序。不使用ContextLoaderListener
和applicationcontext.xml
?如果是,那怎么办
其次,为什么需要在web.xml
中注册dispatcherservlet.xml
或applicationcontext.xml
?因为当这些文件未在web.xml
中注册时,所有setter注入(在dispatcher servlet.xml
或applicationcontext.xml
中指定)都发生在服务器启动时,这意味着这些xml文件在加载时未在web.xml
中注册
是否可以仅使用dispatcher-servlet.xml运行spring orm程序。不使用ContextLoaderListener和applicationcontext.xml
是的,很好
如果是,那怎么办
你就这么做吧。将您需要的所有内容放入dispatcherservlet.xml
,它将自行运行。虽然通常的做法是将DAO相关的内容放在applicationContext.xml
中,将MVC内容放在DispatcherServlet.xml
中,但这绝不是必需的。如果您选择,它可以全部放在一个文件中
其次,为什么需要在web.xml中注册dispatcher-servlet.xml或applicationcontext.xml?因为当这些文件未在web.xml中注册时,所有setter注入(在dispatcher-servlet.xml或applicationcontext.xml中指定)都发生在服务器启动时,这意味着这些xml文件在加载时没有在web.xml中注册
因为如果您不在
web.xml
中指定它们,Spring将使用其默认值并查找它们<默认情况下,code>DispatcherServlet将查找-servlet.xml
,而ContextLoaderListener
将查找/WEB-INF/applicationContext.xml
。如果您选择,您可以在web.xml
中覆盖它。dispatcher-servlet.xml配置dispatcher servlet的上下文。我认为您需要更多地了解Spring——xml文件没有在web.xml中“注册”,它们是Spring上下文加载器的参数。如果不创建上下文,您希望如何使用dispatcher-servlet.xml?