gpt4 book ai didi

java - 我的 spring 程序可以使用dispatcher-servlet.xml 运行而不使用ContextLoaderListener 和applicationcontext.xml 吗?

转载 作者:行者123 更新时间:2023-12-01 15:38:34 24 4
gpt4 key购买 nike

是否可以仅使用dispatcher-servlet.xml运行spring-orm程序。不使用 ContextLoaderListener 和 applicationcontext.xml 吗?如果是的话怎么办?

其次,为什么需要在web.xml中注册dispatcher-servlet.xmlapplicationcontext.xml?因为当这些文件未在 web.xml 中注册时,所有 setter 注入(inject)(在 dispatcher-servlet.xmlapplicationcontext.xml 中指定)都会采取放置在服务器启动时,这意味着这些 xml 文件正在加载,而无需在 web.xml 中注册。

最佳答案

Is it possible to run spring-orm program using dispatcher-servlet.xml only. Without using ContextLoaderListener and applicationcontext.xml?

是的,没问题。

If yes then how?

你就这么做吧。将您需要的一切放入 dispatcher-servlet.xml ,它将自行运行。虽然通常的做法是把 DAO 相关的东西放在 applicationContext.xml 中。和 dispatcher-servlet.xml 中的 MVC 内容,这绝不是一个要求。如果您选择,它们可以全部放在一个文件中。

Secondly why is it necessary to register dispatcher-servlet.xml or applicationcontext.xml in web.xml? Because when these files are not registered in web.xml all the setter injections(specified in dispatcher-servlet.xml or applicationcontext.xml) take place on server start-up that means these xml files are loading without registering in web.xml.

因为如果你没有在 web.xml 中指定它们,Spring 将使用其默认值并无论如何查找它们。 DispatcherServlet将寻找<servlet-name>-servlet.xml ,和ContextLoaderListener将寻找/WEB-INF/applicationContext.xml默认情况下。您可以在web.xml中覆盖它如果你选择的话。

关于java - 我的 spring 程序可以使用dispatcher-servlet.xml 运行而不使用ContextLoaderListener 和applicationcontext.xml 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8458955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com