Announcement Announcement Module
Collapse
No announcement yet.
A Test fails with Spring 3.1 and profiles due to the lack of an active profile Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A Test fails with Spring 3.1 and profiles due to the lack of an active profile

    Hello,

    It's not a question, rather an advice in case you see this error: the tests fail because it's not possible to autowire a dataOnDemand.

    It happened after creating a new entity in a Roo application that was working until then. The only special feature that the application has is the use of profiles, with Spring 3.1

    It took me awhile to realize that test lacked of an active profile.

    Grettings.
    Javier.

    P.S.:

    Related posts:

    Roo + spring 3.1 + environment profiles + auto generated tests

    Source code:

    Code:
    package com.malsolo.application.conf;
    
    import org.junit.Test;
    import org.springframework.roo.addon.test.RooIntegrationTest;
    import org.springframework.test.context.ActiveProfiles;
    import org.springframework.test.context.ContextConfiguration;
    
    @RooIntegrationTest(entity = Sequencer.class)
    //NOTE: the next is for locating some resources that are currently stored in the test folders
    @ContextConfiguration(locations = "classpath*:/META-INF/spring/applicationContext*.xml")
    //NOTE: the next is what I forgot to specify
    @ActiveProfiles("dev")
    public class SequencerIntegrationTest {
    
        @Test
        public void testMarkerMethod() {
        }
    }
    Some traces

    2012-09-14 08:49:55,832 [main] DEBUG org.springframework.test.context.junit4.SpringJUni t4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.malsolo.application.conf.SequencerIntegrationT est].
    ...
    2012-09-14 08:49:56,142 [main] DEBUG org.springframework.test.context.TestContext - Storing ApplicationContext for test class [class com.malsolo.application.conf.SequencerIntegrationT est] in cache under key [[MergedContextConfiguration@1ee3914 testClass = SequencerIntegrationTest, locations = '{classpath:/META-INF/spring/applicationContext*.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.Delegati ngSmartContextLoader']].
    2012-09-14 08:49:56,154 [main] DEBUG org.springframework.beans.factory.annotation.Injec tionMetadata - Found injected element on class [com.malsolo.application.conf.SequencerIntegrationT est]: AutowiredFieldElement for private com.malsolo.application.conf.SequencerDataOnDemand com.malsolo.application.conf.SequencerIntegrationT est.dod
    2012-09-14 08:49:56,154 [main] DEBUG org.springframework.beans.factory.annotation.Injec tionMetadata - Processing injected method of bean 'com.malsolo.application.conf.SequencerIntegration Test': AutowiredFieldElement for private com.malsolo.application.conf.SequencerDataOnDemand com.malsolo.application.conf.SequencerIntegrationT est.dod
    2012-09-14 08:49:56,157 [main] ERROR org.springframework.test.context.TestContextManage r - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener@15a0305] to prepare test instance [com.malsolo.application.conf.SequencerIntegrationT est@1975b59]
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'com.malsolo.application.conf.SequencerIntegration Test': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.malsolo.application.conf.SequencerDataOnDemand com.malsolo.application.conf.SequencerIntegrationT est.dod; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.malsolo.application.conf.SequencerDataOnDemand] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true)}
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessPropert yValues(AutowiredAnnotationBeanPostProcessor.java: 287)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1106)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireBeanProperties( AbstractAutowireCapableBeanFactory.java:374)
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.injectDependencies (DependencyInjectionTestExecutionListener.java:110 )
    at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.prepareTestInstanc e(DependencyInjectionTestExecutionListener.java:75 )
    at org.springframework.test.context.TestContextManage r.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.createTest(SpringJUnit4ClassRunner.j ava:211)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner$1.runReflectiveCall(SpringJUnit4Clas sRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.methodBlock(SpringJUnit4ClassRunner. java:290)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner. java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:222)
    at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.ja va:300)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private com.malsolo.application.conf.SequencerDataOnDemand com.malsolo.application.conf.SequencerIntegrationT est.dod; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.malsolo.application.conf.SequencerDataOnDemand] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true)}
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:506)
    at org.springframework.beans.factory.annotation.Injec tionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor.postProcessPropert yValues(AutowiredAnnotationBeanPostProcessor.java: 284)
    ... 26 more
    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.malsolo.application.conf.SequencerDataOnDemand] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true)}
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.raiseNoSuchBeanDefinitionExcept ion(DefaultListableBeanFactory.java:952)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.doResolveDependency(DefaultList ableBeanFactory.java:821)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.resolveDependency(DefaultListab leBeanFactory.java:735)
    at org.springframework.beans.factory.annotation.Autow iredAnnotationBeanPostProcessor$AutowiredFieldElem ent.inject(AutowiredAnnotationBeanPostProcessor.ja va:478)
    ... 28 more
Working...
X