org.springframework.beans.factory.BeanCreationException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • ConfigurationClassPostProcessor.processConfigBeanDefinitions assumes that bd.getBeanClassName() is the runtime type of that bean definition. This assumption doesn't appear to hold if the bean definition in question is a factory method (at least for a static factory method, bd.getBeanClassName() appears to hold the class containing the factory method, not its return type). As a consequence, trying to use the configuration class {code} @Configuration public class Application { @Bean DataAccessLayer dataAccessLayer() { return new DataAccessLayer(); } @Bean ServiceLayer serviceLayer() { return new ServiceLayer(dataAccessLayer()); } @Bean PresentationLayer presentationLayer() { return new PresentationLayer(serviceLayer()); } @Bean static ConfigurationClassPostProcessor configurationClassPostProcessor() { return new ConfigurationClassPostProcessor(); } } {code} results in {code} Information: Refreshing Root WebApplicationContext: startup date [Wed May 02 22:49:25 CEST 2012]; root of context hierarchy Mai 02, 2012 10:49:25 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions Information: Successfully resolved class for [ch.bedag.xyz.myapp.config.Application] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'dataAccessLayer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=application; factoryMethodName=dataAccessLayer; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configurationClassPostProcessor; factoryMethodName=dataAccessLayer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'serviceLayer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=application; factoryMethodName=serviceLayer; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configurationClassPostProcessor; factoryMethodName=serviceLayer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'presentationLayer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=application; factoryMethodName=presentationLayer; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configurationClassPostProcessor; factoryMethodName=presentationLayer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'configurationClassPostProcessor': replacing [Root bean: class [ch.bedag.xyz.myapp.config.Application]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=configurationClassPostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [ch.bedag.xyz.myapp.config.Application]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=configurationClassPostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons Information: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@eb9101: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,application,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,configurationClassPostProcessor,serviceLayer,dataAccessLayer,presentationLayer]; root of factory hierarchy Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons Information: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@eb9101: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,application,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,configurationClassPostProcessor,serviceLayer,dataAccessLayer,presentationLayer]; root of factory hierarchy Mai 02, 2012 10:49:25 PM org.springframework.web.context.ContextLoader initWebApplicationContext Schwerwiegend: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceLayer' defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]: No matching factory method found: factory bean 'configurationClassPostProcessor'; factory method 'serviceLayer()'. Check that a method with the specified name exists and that it is non-static. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 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:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) {code} The post-processor's inability to cope with factory methods also prevents it from enhancing DataAccessLayer and friends, which was why I configured the PostProcessor in the first place ... I guess I should fall back to Component Scanning to discover the configuration classes, and use @Autowired to wire them up.
    via by Adrian Moos,
  • ConfigurationClassPostProcessor.processConfigBeanDefinitions assumes that bd.getBeanClassName() is the runtime type of that bean definition. This assumption doesn't appear to hold if the bean definition in question is a factory method (at least for a static factory method, bd.getBeanClassName() appears to hold the class containing the factory method, not its return type). As a consequence, trying to use the configuration class {code} @Configuration public class Application { @Bean DataAccessLayer dataAccessLayer() { return new DataAccessLayer(); } @Bean ServiceLayer serviceLayer() { return new ServiceLayer(dataAccessLayer()); } @Bean PresentationLayer presentationLayer() { return new PresentationLayer(serviceLayer()); } @Bean static ConfigurationClassPostProcessor configurationClassPostProcessor() { return new ConfigurationClassPostProcessor(); } } {code} results in {code} Information: Refreshing Root WebApplicationContext: startup date [Wed May 02 22:49:25 CEST 2012]; root of context hierarchy Mai 02, 2012 10:49:25 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions Information: Successfully resolved class for [ch.bedag.xyz.myapp.config.Application] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'dataAccessLayer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=application; factoryMethodName=dataAccessLayer; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configurationClassPostProcessor; factoryMethodName=dataAccessLayer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'serviceLayer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=application; factoryMethodName=serviceLayer; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configurationClassPostProcessor; factoryMethodName=serviceLayer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'presentationLayer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=application; factoryMethodName=presentationLayer; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configurationClassPostProcessor; factoryMethodName=presentationLayer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Information: Overriding bean definition for bean 'configurationClassPostProcessor': replacing [Root bean: class [ch.bedag.xyz.myapp.config.Application]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=configurationClassPostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class ch.bedag.xyz.myapp.config.Application] with [Root bean: class [ch.bedag.xyz.myapp.config.Application]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=configurationClassPostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]] Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons Information: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@eb9101: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,application,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,configurationClassPostProcessor,serviceLayer,dataAccessLayer,presentationLayer]; root of factory hierarchy Mai 02, 2012 10:49:25 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons Information: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@eb9101: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,application,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,configurationClassPostProcessor,serviceLayer,dataAccessLayer,presentationLayer]; root of factory hierarchy Mai 02, 2012 10:49:25 PM org.springframework.web.context.ContextLoader initWebApplicationContext Schwerwiegend: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceLayer' defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]: No matching factory method found: factory bean 'configurationClassPostProcessor'; factory method 'serviceLayer()'. Check that a method with the specified name exists and that it is non-static. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 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:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) {code} The post-processor's inability to cope with factory methods also prevents it from enhancing DataAccessLayer and friends, which was why I configured the PostProcessor in the first place ... I guess I should fall back to Component Scanning to discover the configuration classes, and use @Autowired to wire them up.
    via by Adrian Moos,
  • How to think when wiring beans
    via Stack Overflow by Roger
    ,
  • spring + hibernate integration
    via by Unknown author,
  • Spring Security many providers
    via Stack Overflow by alvaro991
    ,
    • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceLayer' defined in class path resource [ch/bedag/xyz/myapp/config/Application.class]: No matching factory method found: factory bean 'configurationClassPostProcessor'; factory method 'serviceLayer()'. Check that a method with the specified name exists and that it is non-static. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 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:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor2 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    270 more bugmates