javax.servlet.ServletException:没有适配器用于处理程序

时间:2014-04-02 13:34:46

标签: spring hibernate exception spring-mvc

我在xml文件中添加了下面的代码但是当我删除下面的代码然后它工作正常。所以请让我知道我在哪里做错了代码。

 <bean class="org.springframework.http.converter.StringHttpMessageConverter">
             <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
        </bean>

        <bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                <array>
                    <bean class = "org.springframework.http.converter.StringHttpMessageConverter">
                        <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
                    </bean>
                </array>
            </property>
        </bean> 

我在

上有例外
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
     <bean class="pakage">
         <property name="domainManager" ref="domainManager" />
         <property name="userProfileDao" ref="userProfileDao" />
      </bean>

我的MVC-dispatcher-servlet.xml以及两个上面的bean标记

 <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="
                http://www.springframework.org/schema/beans     
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

            <context:component-scan base-package="package.*" />
            <context:annotation-config /> 

            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                 <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
            </bean>

            <bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
                <property name="messageConverters">
                    <array>
                        <bean class = "org.springframework.http.converter.StringHttpMessageConverter">
                            <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
                        </bean>
                    </array>
                </property>
            </bean>


             <context:property-placeholder location="classpath:placeholder.properties"/>
             <!--   Start Interalization  -->
             <bean id="messageSource"
                class="org.springframework.context.support.ResourceBundleMessageSource">
                <property name="basename" value="language" />
            </bean>

             <bean id="localeResolver"
                class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
                <property name="defaultLocale" value="en" />
            </bean>

            <bean id="localeChangeInterceptor"
                class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="language" />
            </bean>



            <bean id="handlerMapping"
                  class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
                <property name="interceptors">
                    <ref bean="localeChangeInterceptor" />
                </property>
            </bean>

             <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
             <bean class="package">
                 <property name="domainManager" ref="domainManager" />
                 <property name="userProfileDao" ref="userProfileDao" />
              </bean>
             <!--  End Interalization    -->

            <!-- Register the welcome.properties -->


            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix">
                    <value>/WEB-INF/jsp/</value>
                </property>
                <property name="suffix">
                    <value>.jsp</value>
                </property>
                <property name="contentType" value="text/html;charset=UTF-8" />
            </bean>
            <import resource="Hibernate.xml"/> 

        </beans>

以下是例外

javax.servlet.ServletException: No adapter for handler [package.ChromeExtensionController@bc7722]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
    at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1128)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:903)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

2 个答案:

答案 0 :(得分:1)

我花了一些时间来解释Spring文档中的大量读数。

在Spring MVC中,需要映射 请求 - &gt;处理程序对象 我们需要使用Handler Mapping接口。

这是在 org.springframework.web.servlet 中,因为Spring使用了servlet技术。

在dispatcher-servlet中,您可以实现任何处理程序映射。

但默认使用dispatcher-servlet,包含 BeanNameUrlHandletMapping DefaultAnnotationHandlerMapping

有关详情,请参阅。 http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/DispatcherServlet.html

<强>解决方案

由于BeanNameUrlHandletMapping默认为,因此您无需在调度程序中再次覆盖它。 如果您已经完成,只需删除即可正常。并为我工作。 :D

有关详细信息,请参阅我的blog post

答案 1 :(得分:0)

您需要在配置中添加<mvc:annotation-driven />。使用<context:annotation-config />将启用对@Autowired等注释的支持。

您可以从配置中删除StringHttpMessageConverterAnnotationMethodHandlerAdapter,因为它不会执行任何操作。支持所有媒体类型的StringHttpMessageConverter将由AnnotationMethodHandlerAdapter注册,然后通过添加<mvc:annotation-driven />进行注册。