在我的 web.xml 上,我有一个“springmvc”servlet 声明(它有一个对应的 springmvc-servlet.xml)
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/myapp/*</url-pattern>
</servlet-mapping>
我还有常用的 applicationContext.xml 文件。
哪个先加载? springmvc-servlet.xml 还是 applicationContext.xml?
我问这个的原因是每当我放置 <mvc:annotation-driven/>
applicationContext.xml 中的元素,我收到严重的上下文错误。但是当我将该元素放入 springmvc-servlet.xml 时,我的网络应用程序运行良好。
有什么想法吗?
在另一个网络应用程序上,我有 <mvc:annotation-driven/>
在 applicationContext.xml 中运行良好。
附录: 我确实注意到 aop:config 的存在与 mvc:annotation-driven
存在冲突最佳答案
applicationContext.xml
context 是 dispatcher-servlet.xml
的父级语境。我不知道这是否意味着它首先加载,但在您的情况下并不重要:
<mvc:annotation-driven />
必须在 dispatcher-servlet.xml
中, 因为它属于应用程序的网络部分。
关于java - Spring 应用程序上下文加载顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4243710/