org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy1220 cannot be cast to org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter

GitHub | javapda | 6 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    spring-boot 1.4.0 ClassCastException spring-security SecurityConfigurerAdapter

    GitHub | 6 months ago | javapda
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy1220 cannot be cast to org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter

    Root Cause Analysis

    1. java.lang.ClassCastException

      com.sun.proxy.$Proxy1220 cannot be cast to org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter

      at org.springframework.security.config.annotation.web.configurers.ServletApiConfigurer.configure()
    2. org.springframework.security
      WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e2e8bac5$$FastClassBySpringCGLIB$$cf12ae7c.invoke
      1. org.springframework.security.config.annotation.web.configurers.ServletApiConfigurer.configure(ServletApiConfigurer.java:94)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      2. org.springframework.security.config.annotation.web.configurers.ServletApiConfigurer.configure(ServletApiConfigurer.java:58)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      3. org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.configure(AbstractConfiguredSecurityBuilder.java:383)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      4. org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:329)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      5. org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      6. org.springframework.security.config.annotation.web.builders.WebSecurity.performBuild(WebSecurity.java:287)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      7. org.springframework.security.config.annotation.web.builders.WebSecurity.performBuild(WebSecurity.java:74)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      8. org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:333)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      9. org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      10. org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:105)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      11. org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e2e8bac5.CGLIB$springSecurityFilterChain$0(<generated>)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      12. org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e2e8bac5$$FastClassBySpringCGLIB$$cf12ae7c.invoke(<generated>)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      12 frames
    3. Spring Core
      MethodProxy.invokeSuper
      1. org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)[spring-core-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      1 frame
    4. Spring Context
      ConfigurationClassEnhancer$BeanMethodInterceptor.intercept
      1. org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      1 frame
    5. org.springframework.security
      WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e2e8bac5.springSecurityFilterChain
      1. org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$e2e8bac5.springSecurityFilterChain(<generated>)[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
      1 frame
    6. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[?:1.8.0_92]
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[?:1.8.0_92]
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[?:1.8.0_92]
      4. java.lang.reflect.Method.invoke(Method.java:498)[?:1.8.0_92]
      4 frames
    7. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      2. org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      7. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      8. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      9. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      10. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      11. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      11 frames
    8. Spring Context
      AbstractApplicationContext.refresh
      1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      2. org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:541)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      3. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      3 frames
    9. Spring
      ContextLoaderListener.contextInitialized
      1. org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      2. org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      3. org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
      3 frames
    10. Glassfish Core
      ContainerBase$StartChild.call
      1. org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4840)[catalina.jar:8.0.36]
      2. org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)[catalina.jar:8.0.36]
      3. org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)[catalina.jar:8.0.36]
      4. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)[catalina.jar:8.0.36]
      5. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)[catalina.jar:8.0.36]
      5 frames
    11. Java RT
      Thread.run
      1. java.util.concurrent.FutureTask.run(FutureTask.java:266)[?:1.8.0_92]
      2. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[?:1.8.0_92]
      3. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[?:1.8.0_92]
      4. java.lang.Thread.run(Thread.java:745)[?:1.8.0_92]
      4 frames