2017-02-22 77 views
0

嘗試使用AbstractAnnotationConfigDispatcherServletInitializer而不是web.xml來初始化Web應用程序。如下的配置文件:上下文初始化失敗...注入自動裝載的依賴關係失敗;嵌套異常是java.lang.UnsupportedOperationException

public class FSSWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

    @Override 
    protected Class<?>[] getRootConfigClasses() { 
    System.out.println("********** getRootConfigClasses"); 

    return new Class[] {FSSRootConfig.class}; 
    } 

    @Override 
    protected Class<?>[] getServletConfigClasses() { 
    System.out.println("********** getServletConfigClasses"); 

    return new Class[] {FSSServletConfig.class}; 
// return null; 
    } 

    @Override 
    protected String[] getServletMappings() { 
    System.out.println("********** getServletMappings"); 

    return new String[] {"/" }; 
    } 
} 

@Configuration 
@EnableWebMvc 
//@ComponentScan(basePackages= {"com.fss.web", "com.xps"}) 
@ComponentScan(basePackageClasses= {TestController.class}) 

@ImportResource({ 
    "/WEB-INF/dispatcher-servlet.xml" 
    } 
) 
public class FSSServletConfig extends WebMvcConfigurerAdapter { 
    public FSSServletConfig() { 
    System.out.println("********** FSSServletConfig"); 
    } 

    @Bean 
    public GeneralSearchCgiDao generalSearchService() { 
    return new GeneralSearchCgiDao(); 
    } 
} 

@Configuration 
@ImportResource({ 
    "classpath:com/fss/application/ctx/applicationContext-cgi.xml", 
    "classpath:com/fss/application/ctx/applicationContext-pl.xml", 
    "classpath:com/fss/application/ctx/connectionSetup.xml", 
    "/WEB-INF/session-beans.xml", 
    "/WEB-INF/alert-mapping-properties.xml", 
    "/WEB-INF/key-mapping.xml", 
    "/WEB-INF/report-mapping-properties.xml" 
    ,"/WEB-INF/common.xml" 
    } 
) 
public class FSSRootConfig { 
    public FSSRootConfig() { 
    System.out.println("********** FSSRootConfig"); 
    } 

    @Bean 
    public RemoteCPStatus remoteCPStatus() { 
    return new RemoteCPStatus(); 
    } 

    @Bean 
    public CgiEnviromentService cgiEnviromentService() { 
    return new CgiEnviromentService(); 
    } 
} 

了以下錯誤:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'investigationCgiDao': Unsatisfied dependency expressed through field 'alertSearchMigrator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alertSearchMigrator': Injection of autowired dependencies failed; nested exception is java.lang.UnsupportedOperationException 
502 2017-02-22 13:18:53,468 ERROR [org.springframework.web.servlet.DispatcherServlet] {} - Context initialization failed 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'investigationCgiDao': Unsatisfied dependency expressed through field 'alertSearchMigrator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alertSearchMigrator': Injection of autowired dependencies failed; nested exception is java.lang.UnsupportedOperationException 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:540) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at javax.servlet.GenericServlet.init(GenericServlet.java:158) [servlet-api.jar:3.0.FR] 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284) [catalina.jar:7.0.53] 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1090) [catalina.jar:7.0.53] 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210) [catalina.jar:7.0.53] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493) [catalina.jar:7.0.53] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.53] 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) [catalina.jar:7.0.53] 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) [catalina.jar:7.0.53] 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) [catalina.jar:7.0.53] 
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073) [catalina.jar:7.0.53] 
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857) [catalina.jar:7.0.53] 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_45] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_45] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45] 
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45] 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alertSearchMigrator': Injection of autowired dependencies failed; nested exception is java.lang.UnsupportedOperationException 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    ... 32 more 
Caused by: java.lang.UnsupportedOperationException 
    at java.util.AbstractMap.put(AbstractMap.java:209) ~[?:1.8.0_45] 
    at org.springframework.web.context.request.FacesRequestAttributes.setAttribute(FacesRequestAttributes.java:125) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:45) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.context.request.SessionScope.get(SessionScope.java:93) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.g`enter code here`etSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    ... 32 more 

wonder what did I miss in these new config. This is a working application with web.xml where we have: 

     <context-param> 
       <param-name>contextConfigLocation</param-name> 
       <param-value> 
         classpath:com/fss/application/ctx/applicationContext-cgi.xml 
         classpath:com/fss/application/ctx/applicationContext-pl.xml 
         classpath:com/fss/application/ctx/connectionSetup.xml 
         /WEB-INF/session-beans.xml 
         /WEB-INF/alert-mapping-properties.xml 
        /WEB-INF/key-mapping.xml 
         /WEB-INF/report-mapping-properties.xml 
       </param-value> 
     </context-param> 


... 

     <servlet> 
       <servlet-name>Dispatcher</servlet-name> 
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
       <init-param> 
         <param-name>contextConfigLocation</param-name> 
         <param-value>/WEB-INF/fids-servlet-config.xml</param-value> 
       </init-param> 
     </servlet> 

嘗試過許多不同的調整,沒有什麼工作。

+0

你能解釋一下'alertSearchMigrator'bean在做什麼操作嗎?看起來它在初始化和失敗時正在做一些事情。 –

回答

0

事實證明,如果一個單身人士擁有一個自動裝配的字段到會話作用域bean,則會發生此錯誤。它需要代理被設置: @Scope(值= 「會話」,proxyMode = ScopedProxyMode.TARGET_CLASS)

這使得感官。但讓我感到困惑的是舊的方式允許它。

我發佈了這個解決方案,以防別人遇到同樣的問題。

謝謝!

相關問題