Skip to content

AlreadyBuiltException: This object has already been built #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JanStureNielsen opened this issue May 11, 2016 · 9 comments
Closed

AlreadyBuiltException: This object has already been built #189

JanStureNielsen opened this issue May 11, 2016 · 9 comments

Comments

@JanStureNielsen
Copy link

JanStureNielsen commented May 11, 2016

Building the spring-projects/spring-data-examples works fine but running the spring-projects/spring-data-examples/rest/security with:

mvn spring-boot:run

fails with AlreadyBuiltException -- see below for stacktrace, environment, and dependencies.

Environment

$:~/src/spring-data-examples/rest/security> mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T09:41:47-07:00)
Maven home: /home/jan/apache-maven-3.3.9
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: /home/jan/jdk1.8.0_74/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.16.7-35-desktop", arch: "amd64", family: "unix"

Failure stacktrace

2016-05-11 16:40:14.350 ERROR 28768 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Exception starting filter springSecurityFilterChain

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: 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 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'itemRepository': Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1062) ~[spring-context-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326) ~[spring-web-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235) ~[spring-web-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:199) ~[spring-web-4.3.0.RC1.jar:4.3.0.RC1]
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) ~[tomcat-embed-core-8.0.33.jar:8.0.33]
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:109) ~[tomcat-embed-core-8.0.33.jar:8.0.33]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4658) [tomcat-embed-core-8.0.33.jar:8.0.33]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5277) [tomcat-embed-core-8.0.33.jar:8.0.33]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [tomcat-embed-core-8.0.33.jar:8.0.33]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [tomcat-embed-core-8.0.33.jar:8.0.33]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [tomcat-embed-core-8.0.33.jar:8.0.33]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_74]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_74]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_74]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_74]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'itemRepository': Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        ... 23 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'itemRepository': Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansWithAnnotation(DefaultListableBeanFactory.java:580) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.context.support.AbstractApplicationContext.getBeansWithAnnotation(AbstractApplicationContext.java:1186) ~[spring-context-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.boot.autoconfigure.security.BootGlobalAuthenticationConfiguration$BootGlobalAuthenticationConfigurationAdapter.init(BootGlobalAuthenticationConfiguration.java:75) ~[spring-boot-autoconfigure-1.4.0.M2.jar:1.4.0.M2]
        at org.springframework.boot.autoconfigure.security.BootGlobalAuthenticationConfiguration$BootGlobalAuthenticationConfigurationAdapter.init(BootGlobalAuthenticationConfiguration.java:60) ~[spring-boot-autoconfigure-1.4.0.M2.jar:1.4.0.M2]
        at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:369) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:323) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration.getAuthenticationManager(AuthenticationConfiguration.java:81) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.authenticationManager(WebSecurityConfigurerAdapter.java:236) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:175) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:290) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:67) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:369) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:323) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:105) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$a3a955e7.CGLIB$springSecurityFilterChain$4(<generated>) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$a3a955e7$$FastClassBySpringCGLIB$$5d99d1a7.invoke(<generated>) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355) ~[spring-context-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$a3a955e7.springSecurityFilterChain(<generated>) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_74]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        ... 24 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemRepository': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:116) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1590) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:187) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1208) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1048) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        ... 59 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor.getAdvice(MethodSecurityMetadataSourceAdvisor.java:107) ~[spring-security-core-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.aop.aspectj.AspectJProxyUtils.isAspectJAdvice(AspectJProxyUtils.java:67) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.aop.aspectj.AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(AspectJProxyUtils.java:49) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.extendAdvisors(AspectJAwareAdvisorAutoProxyCreator.java:97) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:89) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:346) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:298) ~[spring-aop-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1723) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:113) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        ... 67 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.aopalliance.intercept.MethodInterceptor]: Factory method 'methodSecurityInterceptor' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        ... 86 common frames omitted
Caused by: org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built
        at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:44) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration.getAuthenticationManager(AuthenticationConfiguration.java:81) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration.authenticationManager(GlobalMethodSecurityConfiguration.java:256) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration.methodSecurityInterceptor(GlobalMethodSecurityConfiguration.java:123) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$6b1e48c0.CGLIB$methodSecurityInterceptor$13(<generated>) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$6b1e48c0$$FastClassBySpringCGLIB$$c44e3363.invoke(<generated>) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355) ~[spring-context-4.3.0.RC1.jar:4.3.0.RC1]
        at org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$6b1e48c0.methodSecurityInterceptor(<generated>) ~[spring-security-config-4.0.2.RELEASE.jar:4.0.2.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_74]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.0.RC1.jar:4.3.0.RC1]
        ... 87 common frames omitted

Dependency tree

[INFO]                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
[INFO] ------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                        
[INFO] Building Spring Data REST - Security Example 1.0.0.BUILD-SNAPSHOT                                                                                                                                                                                                                                                                                                                                                                                               
[INFO] ------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                        
[INFO]                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ spring-data-rest-security ---                                                                                                                                                                                                                                                                                                                                                                             
[INFO] org.springframework.data.examples:spring-data-rest-security:jar:1.0.0.BUILD-SNAPSHOT                                                                                                                                                                                                                                                                                                                                                                            
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.4.0.M2:compile                                                                                                                                                                                                                                                                                                                                                                                   
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.4.0.M2:compile                                                                                                                                                                                                                                                                                                                                                                                         
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.0.M2:compile                                                                                                                                                                                                                                                                                                                                                                              
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.7:compile                                                                                                                                                                                                                                                                                                                                                                                                    
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.7:compile                                                                                                                                                                                                                                                                                                                                                                                                    
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile                                                                                                                                                                                                                                                                                                                                                                                                           
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile                                                                                                                                                                                                                                                                                                                                                                                                       
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime                                                                                                                                                                                                                                                                                                                                                                                                                    
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.4.0.M2:compile                                                                                                                                                                                                                                                                                                                                                                                     
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.9:compile                                                                                                                                                                                                                                                                                                                                                                                                            
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.0.M2:compile                                                                                                                                                                                                                                                                                                                                                                                    
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.0.33:compile                                                                                                                                                                                                                                                                                                                                                                                                       
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.0.33:compile                                                                                                                                                                                                                                                                                                                                                                                                    
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.0.RC1:compile                                                                                                                                                                                                                                                                                                                                                                                                  
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.1.0.Final:compile                                                                                                                                                                                                                                                                                                                                                                                             
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile                                                                                                                                                                                                                                                                                                                                                                                                
[INFO] |  |  +- org.hibernate:hibernate-core:jar:5.1.0.Final:compile                                                                                                                                                                                                                                                                                                                                                                                                   
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile                                                                                                                                                                                                                                                                                                                                                                                                                       
[INFO] |  |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  |  |  \- com.fasterxml:classmate:jar:1.3.0:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  |  \- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.10.1.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.12.1.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.3.0.RC1:compile
[INFO] |  |  +- org.springframework:spring-context:jar:4.3.0.RC1:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.3.0.RC1:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.3.0.RC1:compile
[INFO] |  |  +- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.0.RC1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.4.0.M2:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.0.RC1:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.0.2.RELEASE:compile
[INFO] |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.0.2.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.0.2.RELEASE:compile
[INFO] |     +- org.springframework:spring-expression:jar:4.3.0.RC1:compile
[INFO] |     \- org.springframework:spring-web:jar:4.3.0.RC1:compile
[INFO] +- com.h2database:h2:jar:1.4.191:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-rest:jar:1.4.0.M2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.4.0.M2:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.0.M2:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.33:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.33:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.33:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.33:compile
[INFO] |  |  +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] |  |  |  \- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.3.0.RC1:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.7.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.3:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.7.3:compile
[INFO] |  \- org.springframework.data:spring-data-rest-webmvc:jar:2.5.1.RELEASE:compile
[INFO] |     \- org.springframework.data:spring-data-rest-core:jar:2.5.1.RELEASE:compile
[INFO] |        +- org.springframework.hateoas:spring-hateoas:jar:0.19.0.RELEASE:compile
[INFO] |        +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |        \- org.atteo:evo-inflector:jar:1.2.1:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.8:provided
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.4.0.M2:provided
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.4.0.M2:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.0.M2:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.4.0.M2:test
[INFO]    +- org.springframework.boot:spring-boot-test:jar:1.4.0.M2:test
[INFO]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.0.M2:test
[INFO]    +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO]    |  \- net.minidev:json-smart:jar:2.2.1:test
[INFO]    |     \- net.minidev:accessors-smart:jar:1.1:test
[INFO]    |        \- org.ow2.asm:asm:jar:5.0.3:test
[INFO]    +- junit:junit:jar:4.12:test
[INFO]    +- org.assertj:assertj-core:jar:2.4.1:test
[INFO]    +- org.mockito:mockito-core:jar:1.10.19:test
[INFO]    |  \- org.objenesis:objenesis:jar:2.1:test
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO]    +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO]    |  \- org.json:json:jar:20140107:test
[INFO]    +- org.springframework:spring-core:jar:4.3.0.RC1:compile
[INFO]    \- org.springframework:spring-test:jar:4.3.0.RC1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.162 s
[INFO] Finished at: 2016-05-11T16:45:56-06:00
[INFO] Final Memory: 26M/374M
[INFO] ------------------------------------------------------------------------
@odrotbohm
Copy link
Member

@gregturn / @rwinch — Would you mind having a look? Looks like the tests work fine but bootstrapping the application really fails.

@JanStureNielsen
Copy link
Author

Direct invocation also fails with the same error: java -jar target/*.jar

@Turbots
Copy link

Turbots commented Jun 7, 2016

I have a failing example in the following repository: https://github.com/Turbots/data-jpa-preautorize-sample
If you go back 1 commit, there is a working example.

Basically, when I autowire my CrudRepository in the main SpringBootApplication, there is some conflict in order of configurations it seems.. debugging this can be extremely confusing, but maybe that's just me :)

@rwinch
Copy link
Member

rwinch commented Jun 17, 2016

@JanStureNielsen Thanks for the detailed report!

This issue is a duplicate of:

The problem only manifests when Tomcat is started because springSecurityFilterChain is eagerly created as described in spring-projects/spring-boot#6178 When using a unit test, the springSecurityFilterChain is properly initialized in singleton phase.

Initializing the springSecurityFilterChain eagerly causes the following to happen:

  • The springSecurityFilterChain to be created early
  • This requests H2ConsoleAutoConfiguration.authenticationManager()
  • That requests AuthenticationConfiguration.getAuthenitcationManager() which invokes AuthenticationManagerBuilder.build()
  • That invokes BootGlobalAuthenticationConfiguration$BootGlobalAuthenticationConfigurationAdapter which attempts to eagerly initialize any beans annotated (or meta-annotated) with @EnableAutoConfiguration to ensure that globalAuthentication is initialized
  • This initializes Application
  • This initializes itemRepository
  • 'itemRepository initializes MethodSecurityMetadataSourceAdvisor.getAdvice() because itemRepository is advised by Spring Security's Method Security
  • MethodSecurityMetadataSourceAdvisor.getAdvice() looks up the methodSecurityInterceptor
  • This initializes GlobalMethodSecurityConfiguration.methodSecurityInterceptor()
  • methodSecurityInterceptor() calls the authenticationManager()
  • Finally authenticationManager() invokes AuthenticationConfiguration.getAuthenticationManager()' which callsAuthenticationManagerBuilder.build()` again.

So we have a Bean Cycle that is stopped by Spring Security detecting that AuthenticationManagerBuilder.build() has already been invoked. Instead of a Bean Cycle, it reports an ObjectAlreadyBuiltException

@olivergierke - I'd recommend closing this issue as a duplicate of spring-projects/spring-security#3935 (this alone will fix the issue)

If you want to ensure you have a test that behaves as it does when running you probably need an integration test (at least until spring-projects/spring-boot#6178 is fixed)

@philwebb
Copy link
Member

I've made an update to Spring Boot 1.4 that appears to fix the issue as long as the configureGlobal(AuthenticationManagerBuilder auth) is moved to a @EnableWebSecurity annotated configuration.

My fork of the sample is here. @rwinch Could you review and see if it makes sense?

@philwebb
Copy link
Member

On a related note, since the security docs state:

it is important to only configure AuthenticationManagerBuilder in a class annotated with either @EnableWebSecurity, @EnableGlobalMethodSecurity, or @EnableGlobalAuthentication

I'm wondering if Spring Boot could register a BeanDefinitionRegistryPostProcessor to check that @Configuration classes with @Autowired methods that take a AuthenticationManagerBuilder fail hard if @EnableWebSecurity, @EnableGlobalMethodSecurity, or @EnableGlobalAuthentication are missing?

@rwinch
Copy link
Member

rwinch commented Jun 30, 2016

Thanks @philwebb

I have considered changing the logic to eagerly initialize only configuration classes that have an with @Autowired methods that take a AuthenticationManagerBuilder but was hesitant because:

  • Didn't want to try and implement the logic to determine if autowire was going to happen on the method. Perhaps this is as easy as checking if @Autowired exists, but hadn't looked into that
  • Was concerned about iterating over all bean definitions. This probably isn't really an issue, but again no time to investigate
  • I'd have to load the bean class from a string so as not to initialize the wrong classes and was concerned a bit about classloading issues

@philwebb
Copy link
Member

Perhaps a simpler option is just to change the exception message in:

Caused by: java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer@6e9a10cd to already built object
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.add(AbstractConfiguredSecurityBuilder.java:195) ~[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
    at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.apply(AbstractConfiguredSecurityBuilder.java:132) ~[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
    at org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder.apply(AuthenticationManagerBuilder.java:290) ~[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
    at org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder.inMemoryAuthentication(AuthenticationManagerBuilder.java:134) ~[spring-security-config-4.1.0.RELEASE.jar:4.1.0.RELEASE]
    at com.example.DataJpaPreAuthorizeApplication.configureGlobal(DataJpaPreAuthorizeApplication.java:26) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:681) ~[spring-beans-4.3.1.BUILD-SNAPSHOT.jar:4.3.1.BUILD-SNAPSHOT]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.1.BUILD-SNAPSHOT.jar:4.3.1.BUILD-SNAPSHOT]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.3.1.BUILD-SNAPSHOT.jar:4.3.1.BUILD-SNAPSHOT]
    ... 17 common frames omitted

To hint that missing @EnableWebSecurity, @EnableGlobalMethodSecurity, or @EnableGlobalAuthentication annotations are a common cause?

@mp911de
Copy link
Member

mp911de commented Oct 1, 2019

Works as of Spring Boot 2.2 snapshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants