Announcement Announcement Module
Collapse
No announcement yet.
BeanCreationException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanCreationException

    I am attempting to run a JUnit test. I am loading my conext files in the following manner.


    Code:
    public class JmdUpdateServiceTest extends
    		AbstractDependencyInjectionSpringContextTests {
    	
    	
    @Override
    protected String [] getConfigLocations(){
    		return new String[] {"classpath:/applicationContext.xml",
    				  "classpath:/jtdi_metadata-util.xml", 
    				  "classpath:/jtdi_metadata-data.xml", 
    				  "classpath:/jtdi_metadata-service.xml"};	             
    	}//end method
    
    
    @Before
    	public void initialize() throws Exception{
    	  //Put things in here that are performed for EACH test method
            // There is a ApplicationContext variable in the super class
    	    super.setUp();	
    	    applicationContext = new ClassPathXmlApplicationContext(getConfigLocations()); 
    	    log.debug("applicationContext: "+ applicationContext); 	
    	
    	}//end method
    When I attempt to run the JUnit test, I get the following error:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:914)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:216)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
    	at jtdi.metadata.service.bean.JmdUpdateServiceBean.getJtdiDocumentServiceBean(JmdUpdateServiceBean.java:56)
    	at jtdi.metadata.service.bean.JmdUpdateServiceTest.testGetJtdiDocumentServiceBean(JmdUpdateServiceTest.java:57)
    	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 junit.framework.TestCase.runTest(TestCase.java:168)
    	at junit.framework.TestCase.runBare(TestCase.java:134)
    	at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    	at junit.framework.TestResult$1.protect(TestResult.java:110)
    	at junit.framework.TestResult.runProtected(TestResult.java:128)
    	at junit.framework.TestResult.run(TestResult.java:113)
    	at junit.framework.TestCase.run(TestCase.java:124)
    	at junit.framework.TestSuite.runTest(TestSuite.java:232)
    	at junit.framework.TestSuite.run(TestSuite.java:227)
    	at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    I have a transaction manager define in the jtdi_metadata-data.xml, so I am confused why it can not find the transaction manager.
    Code:
       
       <bean id="transactionManager" 
             class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
               <ref bean="sessionFactory"/>
            </property>
       </bean>
    In the jtdi_metadata-service.xml I have defined two types of interceptors:

    Code:
       <bean id="debugInterceptor2" 
             class="org.springframework.aop.interceptor.DebugInterceptor">
       </bean>
       
       <bean id="performanceInterceptor2" 
             class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor">
       </bean>
    So I am a little confused why the TransactionAttributeSource is looking for a transaction manager.....

    Any suggestions would be greatly appreciated.


    Russ

  • #2
    Don't mix JUnit3 AND JUnit4 that will definitly screw up what you are doing. First refactor your testcase to be either JUnit4 OR JUnit3 not both.

    Also your stacktrace is strange it looks like if in the getJtdiDocumentServiceBean you are creating a new ApplicationContext...

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      Don't mix JUnit3 AND JUnit4 that will definitly screw up what you are doing. First refactor your testcase to be either JUnit4 OR JUnit3 not both.

      Also your stacktrace is strange it looks like if in the getJtdiDocumentServiceBean you are creating a new ApplicationContext...
      I know this post is an old one, but the subject is related to my problem.
      I get same problem and my Test class is:

      Code:
      @TransactionConfiguration(transactionManager = "milinsTransactionManager", defaultRollback = true)
      @Transactional
      public class TestIrFastighetDaoEclipseLink extends AbstractBaseTest {
      
      	@Autowired
      	IrFastighetDao irFastighetDao;
      
      	@Autowired
      	GroupInfoDao groupInfoDao;
      
      	@Test
      	public void testSave() {
      		GregorianCalendar gCalendar = new GregorianCalendar(2010, 11, 29);
      		Date date = gCalendar.getTime();
      
      		GroupInfo firstGroupInfo = new GroupInfo();
      		firstGroupInfo.setGroupInfoId("1111");
      		firstGroupInfo.setGroupInfoType(250);
      		firstGroupInfo.setGroupInfo(new String(
      				"This is the first groupinfo buffer"));
      		firstGroupInfo.setVersion(3);
      
      		GroupInfo secondGroupInfo = new GroupInfo();
      		secondGroupInfo.setGroupInfoId("2222");
      		secondGroupInfo.setGroupInfoType(250);
      		secondGroupInfo.setGroupInfo(new String(
      				"This is the second groupinfo buffer"));
      		secondGroupInfo.setMigrated(true);
      
      		IrFastighet irFastighet = new IrFastighet();
      		irFastighet.setChangeDate(date);
      		irFastighet.setErrorMark(true);
      		irFastighet.setFnr("123456789");
      		irFastighet.setPreviousRelation(new String("Just a test"));
      		irFastighet.setUnclearReg(false);
      		ArrayList<GroupInfo> groupInfos = new ArrayList<GroupInfo>();
      		irFastighet.setGroupInfos(groupInfos);
      		irFastighet.setVersion(2);
      
      		irFastighet.addGroupInfoToIrFastighet(firstGroupInfo);
      		irFastighet.addGroupInfoToIrFastighet(secondGroupInfo);
      
      		irFastighetDao.save(irFastighet);
      
      		IrFastighet irFastighet2 = irFastighetDao
      				.getIrFastighetByFnrAndVersion("123456789", 2);
      		Assert.assertNotNull(irFastighet2);
      		Assert.assertEquals(irFastighet2.getVersion(), 2);
      		Assert.assertEquals(irFastighet2.isMigrated(), false);
      		List<GroupInfo> list = irFastighet2.getGroupInfos();
      		Assert.assertEquals(list.get(0).getVersion(), 3);
      		Assert.assertEquals(list.get(0).isMigrated(), false);
      		Assert.assertEquals(list.get(1).getVersion(), 0);
      		Assert.assertEquals(list.get(1).isMigrated(), true);
      
      	}
      My Abstract test:

      Code:
      @SuppressWarnings("unused")
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations = { "classpath:spring-master.xml" })
      public abstract class AbstractBaseTest {
      
      }
      and my stac trace when I run the test method
      Code:
      org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
      	at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:248)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:100)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy18.save(Unknown Source)
      	at se.lantmateriet.milins.dao.eclipselink.TestIrFastighetDaoEclipseLink.testSave(TestIrFastighetDaoEclipseLink.java:65)
      	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      	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:70)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
      	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

      Comment


      • #4
        Originally posted by Sheri View Post
        I know this post is an old one, but the subject is related to my problem.
        I get same problem and my Test class is:

        ....
        By the way this test class run before ... but not today!

        Comment

        Working...
        X