2012-08-29 57 views
3

嗨我试图从3.0.7升级到3.1.2。在3.0.7中一切正常,但当我在我的pom中碰到值时,当我启动服务器时出现错误。我对春天很陌生。从3.0.7升级到3.1.2引发NoSuchBeanDefinitionException

我得到的错误是

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'my.name.space.security.handler.AnnotationMethodHandlerAdapterConfigurer#0': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter my.name.space.security.handler.AnnotationMethodHandlerAdapterConfigurer.adapter; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 

就像我说我是新来的春天,但是,它看起来好像它有麻烦自动装配到原生泉水类。我正在运行3.0.7,这一切工作正常。这是我的堆栈跟踪。

2012-08-29 11:50:24,364 [localhost-startStop-1] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.ns.web.security.handler.AnnotationMethodHandlerAdapterConfigurer#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter com.clovrmedia.web.security.handler.AnnotationMethodHandlerAdapterConfigurer.adapter; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588) 
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266) 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:650) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1582) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:680) 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter com.clovrmedia.web.security.handler.AnnotationMethodHandlerAdapterConfigurer.adapter; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) 
    ... 34 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:952) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:821) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) 
    ... 36 more 

这里的,我相信是提高该异常的类:

package com.ns.web.security.handler; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter; 

/** 
* This class is a bean post-processor for AnnotationMethodHandlerAdapter. This required to set the property values 
* in the instance of AnnotationMethodHandlerAdapter created by the spring framework when using the tag 
* <annotation-driven/> 
*/ 
public class AnnotationMethodHandlerAdapterConfigurer { 
    @Autowired 
    private AnnotationMethodHandlerAdapter adapter; 
    private int cacheSeconds = -1; 

    public void init() { 
     if(cacheSeconds > -1) { 
      adapter.setCacheSeconds(cacheSeconds); 
     } 
    } 

    public int getCacheSeconds() { 
     return cacheSeconds; 
    } 

    public void setCacheSeconds(int cacheSeconds) { 
     this.cacheSeconds = cacheSeconds; 
    } 
} 

这是决定春季的行为请求

<!-- Handles Spring requests --> 
<servlet> 
    <servlet-name>clovrpatch</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/nsWebMVCConfig.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

这里是nsWebMVCConfig XML声明。 xml文件在上面的xml类中引用。它包含引发异常的类的bean声明。

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<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:p="http://www.springframework.org/schema/p" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

     <import resource="classpath:META-INF/spring/nsPropertyConfig.xml"/> 

     <!-- The controllers are autodetected POJOs labeled with the @Controller annotation. --> 
     <context:component-scan base-package="com.ns.web" use-default-filters="false"> 
      <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
     </context:component-scan> 

     <!-- Turns on support for mapping requests to Spring MVC @Controller methods 
      Also registers default Formatters and Validators for use across all @Controllers --> 
     <mvc:annotation-driven /> 

    <!-- This is a bean post-processor for AnnotationMethodHandlerAdapter--> 
    <bean class="com.ns.web.security.handler.AnnotationMethodHandlerAdapterConfigurer" init-method="init"> 
     <property name="cacheSeconds" value="0" /> 
    </bean> 

     <!-- register "global" interceptor beans to apply to all registered HandlerMappings --> 
     <mvc:interceptors> 
      <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/> 
      <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/> 

     <bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" /> 

    </mvc:interceptors> 

     <mvc:view-controller path="/scrubbedout"/> 
     <mvc:view-controller path="/scrubbedout"/> 
     <mvc:view-controller path="/scrubbedout"/> 
     <mvc:view-controller path="/scrubbedout" /> 
    <mvc:view-controller path="/scrubbedout" /> 
    <mvc:view-controller path="/scrubbedout" /> 

     <!-- store preferred language configuration in a cookie --> 
     <bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver" p:cookieName="locale"/>  

     <!-- resolves localized <theme_name>.properties files in the classpath to allow for theme support --> 
     <bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource"/> 

     <!-- store preferred theme configuration in a cookie --> 
     <bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver" p:cookieName="theme" p:defaultThemeName="standard"/> 

     <!-- allows for integration of file upload functionality --> 
     <bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver"/> 

    <!-- Enable @Annotation-drive bean configuration --> 
    <context:annotation-config /> 

    <!-- Configures Spring Social --> 
    <bean class="com.ns.web.social.SocialConfig" /> 

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
      <property name="mediaTypes"> 
        <map> 
         <entry key="html" value="text/html" /> 
         <entry key="json" value="application/json" /> 
        </map> 
      </property> 
      <property name="viewResolvers"> 
        <list> 
         <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
           <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" /> 
         </bean> 
        </list> 
      </property> 
      <property name="defaultViews"> 
        <list> 
         <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> 
           <property name="prefixJson" value="true" /> 
         </bean> 
        </list> 
      </property> 
     <property name="defaultContentType" value="text/html"/> 
     </bean> 

    <bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer"> 
     <property name="definitions"> 
      <list> 
       <value>/WEB-INF/layouts/nsMainLayouts.xml</value> 
      </list> 
     </property> 
     <property name="preparerFactoryClass" value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory"/> 
    </bean> 

    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> 

    <!-- Default route --> 
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="mappings"> 
      <props> 
       <prop key="/">welcomeController</prop> 
      </props> 
     </property> 
     <property name="rootHandler" ref="welcomeController" /> 
    </bean> 
    <!-- these are static resources. By specifing them here, they will not go through the DispatcherServlet --> 

    <mvc:resources mapping="/css/**"    location="/css/"/> 
    <mvc:resources mapping="/images/**"   location="/images/"/> 
    <mvc:resources mapping="/js/**"    location="/js/"/> 
</beans> 

我感觉很蹩脚,只是把堆栈跟踪和一些文件放在一边,只是说'找出来给我看。但是我完全超出了我的深度,并且在过去的3天里一直在Google上搜索。任何帮助,将不胜感激。

回答

6

我不熟悉Spring的安全性,但自Spring 3.1以来AnnotationMethodHandlerAdapter已被RequestMappingHandlerAdapter所取代。这可能是其中一个原因。你可以看看link。希望它对你有帮助。

+1

你是对的,Spring 3.0.x用于使用''注释创建AnnotationMethodHandlerAdapter,而使用Spring 3.1,它生成'RequestMappingHandlerAdapter'作为默认的handlerAdapter。解决方法是注入'RequestMappingHandlerAdapter'而不是'AnnotationMethodHandlerAdapter' –

+1

我可以直接在那里做出更改,或者在此之前需要做其他配置吗?我问,因为虽然这样做删除了我正在处理的错误导致了一些其他有趣的行为。 – aamiri