Spring:DispatcherServlet配置需要包含支持该处理程序的HandlerAdapter

发布于 2025-01-12 14:05:30 字数 2774 浏览 0 评论 0原文

我们正在尝试将 spring 从 4.x 升级到 5.3.x

这是dispatcher-servlet.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- The facade for the ConfigOps EJB -->
    <bean id="configOps" class="com.sample.Config" scope="prototype" />

    <!-- Main controller beans-->
    <bean id="actionController" class="com.ui.controllers.ActionController" >
        <property name="configOps" ref="configOps" />
    </bean>
    <bean id="nodeController" class="com.ui.controllers.NodeController" >
        <property name="configOps" ref="configOps" />
    </bean>
    <bean id="wizardController" class="com.ui.controllers.WizardController" >
    <property name="configOps" ref="configOps" />
    <property name="nodeController" ref="nodeController" />
   </bean>
    <bean id="exceptionResolver"  class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="java.lang.Exception">errorView</prop>
            </props>
        </property>
    </bean>
    
      
    <!-- Simple URL based handler mapping -->
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <value>
                /**/actions.do=actionController
                /**/nodes.do=nodeController
                /**/wizard.do=wizardController
            </value>
        </property>
    </bean>

    <!-- View resolver for action controllers -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    </bean>
</beans>

注意:这里的 Wizardcontroller 用 @controller 进行注释,它具有像 @Requestmapping 和这样的注释 NodeController,ActionController 扩展了 AbstractController,它有一些方法。

我尝试根据一些答案在调度程序 xml 文件中添加 mvc:annotation-driven ,但仍然是同样的问题..

我们如何更改代码以与 spring 5.3.x 一起使用?

we are trying to upgrade spring from 4.x to 5.3.x

this is the dispatcher-servlet.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- The facade for the ConfigOps EJB -->
    <bean id="configOps" class="com.sample.Config" scope="prototype" />

    <!-- Main controller beans-->
    <bean id="actionController" class="com.ui.controllers.ActionController" >
        <property name="configOps" ref="configOps" />
    </bean>
    <bean id="nodeController" class="com.ui.controllers.NodeController" >
        <property name="configOps" ref="configOps" />
    </bean>
    <bean id="wizardController" class="com.ui.controllers.WizardController" >
    <property name="configOps" ref="configOps" />
    <property name="nodeController" ref="nodeController" />
   </bean>
    <bean id="exceptionResolver"  class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="java.lang.Exception">errorView</prop>
            </props>
        </property>
    </bean>
    
      
    <!-- Simple URL based handler mapping -->
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <value>
                /**/actions.do=actionController
                /**/nodes.do=nodeController
                /**/wizard.do=wizardController
            </value>
        </property>
    </bean>

    <!-- View resolver for action controllers -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
    </bean>
</beans>

Note: here wizardcontroller is annotated with @controller which has annotation like @Requestmapping and
nodecontroller,actioncontroller extends abstractcontroller which has some methods.

i tried by adding mvc:annotation-driven in dispatcher xml file as per some of answers, but still same issue..

how we can the change the code to work with spring 5.3.x?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文