springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined

Spring JIRA | Matthew T. Adams | 5 years 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

    I'm trying to use a container-managed extended {{EntityManager}} in a test class. When I use the annotation {{@PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="...")}}, the {{PersistenceAnnotationBeanPostProcessor}} throws a {{NoSuchBeanDefinitionException}} saying that it can't find the bean with the name of my test class. If I remove the type argument (or set it to {{PersistenceContextType.TRANSACTION}}), my test fails for unrelated reasons. h4. Reproducible example attached. To reproduce, extract archives in archive, issue {{"mvn install"}} in {{../dn-atomikos/trunk}}, and then issue {{"mvn clean test -Dtest=TwoPhaseCommitTest"}} in {{../db.jta/}}. If reproduced, you should get an exception like the one below. If you comment out {{"type=PersistenceContextType.EXTENDED)"}} in {{AbstractTwoPhaseCommitTest}}, this exception goes away (and a new, unrelated exception may appear). I need to test this with a container-managed extended {{EntityManager}}, so I'm blocked until this is fixed. {noformat} 2011-11-09 14:40:39,476 TRACE [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <No bean named 'org.example.test.TwoPhaseCommitTest' found in org.springframework.beans.fact ory.support.DefaultListableBeanFactory@4934ce4a: defining beans [transactionManager,org.springframework.context.support.ConversionServiceFactoryBean#0,targetDataSources,xaOrderDs,xaItemDs,xaTm,xa Ut,ds,orderDs,itemDs,targetEmfs,orderEmf,itemEmf,jpaProps,abstractEmf,jpaImplProps,jpaImplJtaProps,jpaImplDbProps,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.trans action.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org .springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.int ernalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springf ramework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy> 2011-11-09 14:40:39,476 ERROR [org.springframework.test.context.TestContextManager] - <Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyIn jectionTestExecutionListener@502cb49d] to prepare test instance [org.example.test.TwoPhaseCommitTest@766d4f30]> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.example.test.TwoPhaseCommitTest': Injection of persistence dependencies failed; nested exception is org .springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1099) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:377) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:81) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractBeanFactory.isPrototype(AbstractBeanFactory.java:430) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveExtendedEntityManager(PersistenceAnnotationBeanPostProcessor.java:689) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:339) ... 32 more {noformat}

    Spring JIRA | 5 years ago | Matthew T. Adams
    springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined
  2. 0

    I'm trying to use a container-managed extended {{EntityManager}} in a test class. When I use the annotation {{@PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="...")}}, the {{PersistenceAnnotationBeanPostProcessor}} throws a {{NoSuchBeanDefinitionException}} saying that it can't find the bean with the name of my test class. If I remove the type argument (or set it to {{PersistenceContextType.TRANSACTION}}), my test fails for unrelated reasons. h4. Reproducible example attached. To reproduce, extract archives in archive, issue {{"mvn install"}} in {{../dn-atomikos/trunk}}, and then issue {{"mvn clean test -Dtest=TwoPhaseCommitTest"}} in {{../db.jta/}}. If reproduced, you should get an exception like the one below. If you comment out {{"type=PersistenceContextType.EXTENDED)"}} in {{AbstractTwoPhaseCommitTest}}, this exception goes away (and a new, unrelated exception may appear). I need to test this with a container-managed extended {{EntityManager}}, so I'm blocked until this is fixed. {noformat} 2011-11-09 14:40:39,476 TRACE [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <No bean named 'org.example.test.TwoPhaseCommitTest' found in org.springframework.beans.fact ory.support.DefaultListableBeanFactory@4934ce4a: defining beans [transactionManager,org.springframework.context.support.ConversionServiceFactoryBean#0,targetDataSources,xaOrderDs,xaItemDs,xaTm,xa Ut,ds,orderDs,itemDs,targetEmfs,orderEmf,itemEmf,jpaProps,abstractEmf,jpaImplProps,jpaImplJtaProps,jpaImplDbProps,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.trans action.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org .springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.int ernalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springf ramework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy> 2011-11-09 14:40:39,476 ERROR [org.springframework.test.context.TestContextManager] - <Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyIn jectionTestExecutionListener@502cb49d] to prepare test instance [org.example.test.TwoPhaseCommitTest@766d4f30]> org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.example.test.TwoPhaseCommitTest': Injection of persistence dependencies failed; nested exception is org .springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1099) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:377) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:81) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractBeanFactory.isPrototype(AbstractBeanFactory.java:430) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveExtendedEntityManager(PersistenceAnnotationBeanPostProcessor.java:689) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:339) ... 32 more {noformat}

    Spring JIRA | 5 years ago | Matthew T. Adams
    springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.example.test.TwoPhaseCommitTest' is defined
  3. 0

    Exception : No bean named 'ui' is defined

    GitHub | 3 years ago | h1d3m3
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ui' is defined
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.beans.factory.NoSuchBeanDefinitionException

      No bean named 'org.example.test.TwoPhaseCommitTest' is defined

      at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition()
    2. Spring Beans
      AbstractBeanFactory.isPrototype
      1. org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
      2. org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
      3. org.springframework.beans.factory.support.AbstractBeanFactory.isPrototype(AbstractBeanFactory.java:430)
      3 frames
    3. Spring ORM
      PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject
      1. org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveExtendedEntityManager(PersistenceAnnotationBeanPostProcessor.java:689)
      2. org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
      2 frames
    4. Spring Beans
      InjectionMetadata.inject
      1. org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
      2. org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      2 frames
    5. Spring ORM
      PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues
      1. org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:339)
      1 frame
    6. Spring Beans
      AbstractAutowireCapableBeanFactory.autowireBeanProperties
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1099)
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:377)
      2 frames
    7. Spring TestContext
      SpringJUnit4ClassRunner$1.runReflectiveCall
      1. org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
      2. org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
      3. org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
      4. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
      5. org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
      5 frames
    8. JUnit
      ReflectiveCallable.run
      1. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      1 frame
    9. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
      2. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      2 frames
    10. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      2. org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      3. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      4. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      5. org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      6. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      6 frames
    11. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      2 frames
    12. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      1 frame
    13. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      1 frame
    14. JUnit4 Provider
      JUnit4Provider.invoke
      1. org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      2. org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
      3. org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
      3 frames
    15. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:597)
      4 frames
    16. SureFire
      ForkedBooter.main
      1. org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
      2. org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
      3. org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
      4. org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:81)
      5. org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
      5 frames