What do you mean by "But when I try to run the surefire plugin the autowire did not work." and mvn test works? Doesn't "mvn test" invoke the surefire plugin? (Also, you can autowire directly on the field, instead of the property, save some code)
Thanks, mohan kr -----Original Message----- From: Chávez, Carlos [mailto:[email protected]] Sent: Sunday, July 05, 2009 6:34 AM To: [email protected] Subject: surefire and spring - Autowiring of methods failed Hello everyone. I configured the test cases to use annotations and autowire, everything works as expected when i run "mvn test" or install. But when I try to run the surefire plugin the autowire did not work. **************************************************************************** ***** The Following is the dependecy tree: **************************************************************************** ***** [INFO] [dependency:tree {execution: default-cli}] [INFO] ni.gob.cgr.siirci:dao:jar:1.0-SNAPSHOT [INFO] +- ni.gob.cgr.siirci:bean:jar:1.0-SNAPSHOT:compile [INFO] | \- commons-lang:commons-lang:jar:2.4:compile [INFO] +- ni.gob.cgr.siirci:hibernate:jar:1.0-SNAPSHOT:compile [INFO] | +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile [INFO] | | +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile [INFO] | | +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile [INFO] | | | +- antlr:antlr:jar:2.7.6:compile [INFO] | | | \- javax.transaction:jta:jar:1.1:compile [INFO] | | \- dom4j:dom4j:jar:1.6.1:compile [INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.3.0.ga:compile [INFO] | | \- org.hibernate:hibernate:jar:3.2.1.ga:compile [INFO] | | +- asm:asm-attrs:jar:1.5.3:compile [INFO] | | +- cglib:cglib:jar:2.1_3:compile [INFO] | | \- asm:asm:jar:1.5.3:compile [INFO] | +- org.slf4j:slf4j-nop:jar:1.5.8:compile [INFO] | +- org.slf4j:slf4j-api:jar:1.5.8:compile [INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile [INFO] | \- javassist:javassist:jar:3.8.0.GA:compile [INFO] +- postgresql:postgresql:jar:8.3-604.jdbc3:compile [INFO] +- org.springframework:spring:jar:2.5.6.SEC01:compile [INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile [INFO] +- org.springframework:spring-hibernate3:jar:2.0.8:compile [INFO] | +- aopalliance:aopalliance:jar:1.0:compile [INFO] | +- org.springframework:spring-beans:jar:2.0.8:compile [INFO] | +- org.springframework:spring-context:jar:2.0.8:compile [INFO] | +- org.springframework:spring-core:jar:2.0.8:compile [INFO] | +- org.springframework:spring-dao:jar:2.0.8:compile [INFO] | \- org.springframework:spring-jdbc:jar:2.0.8:compile [INFO] +- commons-dbcp:commons-dbcp:jar:1.2.2:compile [INFO] | \- commons-pool:commons-pool:jar:1.3:compile [INFO] +- junit:junit:jar:4.6:test [INFO] \- org.springframework:spring-test:jar:2.5.6.SEC01:test **************************************************************************** ***** The following is the stacktrace: **************************************************************************** ***** [INFO] skip non existing resourceDirectory /home/cchavez/workspace/siirci/dao/src/test/resources [INFO] [compiler:testCompile] [INFO] Nothing to compile - all classes are up to date [INFO] [surefire:test] [INFO] Surefire report directory: /home/cchavez/workspace/siirci/dao/target/surefire-reports 07-05-2009 04:56:55 AM org.springframework.test.context.TestContextManager retrieveTestExecutionListeners INFO: @TestExecutionListeners is not present for class [class ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase]: using defaults. ------------------------------------------------------- T E S T S ------------------------------------------------------- Running ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase 07-05-2009 04:56:55 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [applicationContext.xml] 07-05-2009 04:56:56 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.genericapplicationcont...@fbb7cb: display name [org.springframework.context.support.genericapplicationcont...@fbb7cb]; startup date [Sun Jul 05 04:56:56 CST 2009]; root of context hierarchy 07-05-2009 04:56:56 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory INFO: Bean factory for application context [org.springframework.context.support.genericapplicationcont...@fbb7cb]: org.springframework.beans.factory.support.defaultlistablebeanfact...@aeea66 07-05-2009 04:56:56 AM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties INFO: Loading properties file from class path resource [hibernate.properties] 07-05-2009 04:56:56 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.defaultlistablebeanfact...@aeea66: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework .transaction.annotation.AnnotationTransactionAttributeSource#0,org.springfra mework.transaction.interceptor.TransactionInterceptor#0,org.springframework. transaction.config.internalTransactionAdvisor,org.springframework.context.an notation.internalPersistenceAnnotationProcessor,org.springframework.context. annotation.internalCommonAnnotationProcessor,org.springframework.context.ann otation.internalAutowiredAnnotationProcessor,org.springframework.context.ann otation.internalRequiredAnnotationProcessor,org.springframework.beans.factor y.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transacti onManager,sessionUtil,baseFacade,usuarioFacade]; root of factory hierarchy 07-05-2009 04:56:56 AM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory INFO: Building new Hibernate SessionFactory 07-05-2009 04:56:57 AM org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet INFO: Using DataSource [org.apache.commons.dbcp.basicdatasou...@7a36a2] of Hibernate SessionFactory for HibernateTransactionManager 07-05-2009 04:56:57 AM org.springframework.test.context.TestContextManager prepareTestInstance GRAVE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionLi ste...@5ff916] to prepare test instance [null(ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase)] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase': Autowiring of methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase.setUsuarioFacade(ni.gob.cgr.s iirci.facade.UsuarioFacade); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [ni.gob.cgr.siirci.facade.UsuarioFacade] is defined: Unsatisfied dependency of type [class ni.gob.cgr.siirci.facade.UsuarioFacade]: expected at least 1 matching bean at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc essor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:25 6) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .populateBean(AbstractAutowireCapableBeanFactory.java:998) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory .autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329) at org.springframework.test.context.support.DependencyInjectionTestExecutionLis tener.injectDependencies(DependencyInjectionTestExecutionListener.java:110) at org.springframework.test.context.support.DependencyInjectionTestExecutionLis tener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(Test ContextManager.java:255) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(S pringJUnit4ClassRunner.java:111) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMe thod(SpringJUnit4ClassRunner.java:148) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.ja va:61) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54 ) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJU nit4ClassRunner.java:97) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62 ) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(Ab stractDirectoryTestSuite.java:140) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractD irectoryTestSuite.java:127) at org.apache.maven.surefire.Surefire.run(Surefire.java:177) 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.booter.SurefireBooter.runSuitesInProcess(SurefireB ooter.java:345) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:100 9) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase.setUsuarioFacade(ni.gob.cgr.s iirci.facade.UsuarioFacade); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [ni.gob.cgr.siirci.facade.UsuarioFacade] is defined: Unsatisfied dependency of type [class ni.gob.cgr.siirci.facade.UsuarioFacade]: expected at least 1 matching bean at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc essor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.jav a:543) at org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods (InjectionMetadata.java:117) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc essor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:25 3) ... 23 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [ni.gob.cgr.siirci.facade.UsuarioFacade] is defined: Unsatisfied dependency of type [class ni.gob.cgr.siirci.facade.UsuarioFacade]: expected at least 1 matching bean at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolve Dependency(DefaultListableBeanFactory.java:613) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProc essor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.jav a:499) ... 25 more org.apache.maven.surefire.booter.SurefireExecutionException: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Desc ription;Ljava/lang/Throwable;)V; nested exception is java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Desc ription;Ljava/lang/Throwable;)V java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Desc ription;Ljava/lang/Throwable;)V at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMe thod(SpringJUnit4ClassRunner.java:155) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.ja va:61) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54 ) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJU nit4ClassRunner.java:97) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62 ) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(Ab stractDirectoryTestSuite.java:140) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractD irectoryTestSuite.java:127) at org.apache.maven.surefire.Surefire.run(Surefire.java:177) 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.booter.SurefireBooter.runSuitesInProcess(SurefireB ooter.java:345) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:100 9) 07-05-2009 04:56:57 AM org.springframework.context.support.AbstractApplicationContext doClose INFO: Closing org.springframework.context.support.genericapplicationcont...@fbb7cb: display name [org.springframework.context.support.genericapplicationcont...@fbb7cb]; startup date [Sun Jul 05 04:56:56 CST 2009]; root of context hierarchy 07-05-2009 04:56:57 AM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons INFO: Destroying singletons in org.springframework.beans.factory.support.defaultlistablebeanfact...@aeea66: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework .transaction.annotation.AnnotationTransactionAttributeSource#0,org.springfra mework.transaction.interceptor.TransactionInterceptor#0,org.springframework. transaction.config.internalTransactionAdvisor,org.springframework.context.an notation.internalPersistenceAnnotationProcessor,org.springframework.context. annotation.internalCommonAnnotationProcessor,org.springframework.context.ann otation.internalAutowiredAnnotationProcessor,org.springframework.context.ann otation.internalRequiredAnnotationProcessor,org.springframework.beans.factor y.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transacti onManager,sessionUtil,baseFacade,usuarioFacade]; root of factory hierarchy 07-05-2009 04:56:57 AM org.springframework.orm.hibernate3.AbstractSessionFactoryBean destroy INFO: Closing Hibernate SessionFactory **************************************************************************** ***** The class is very simple: **************************************************************************** ***** @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"/applicationContext.xml"}) @TransactionConfiguration @Transactional public class UsuarioFacadeTestCase extends TestCase { private UsuarioFacade usuarioFacade; public UsuarioFacade getUsuarioFacade() { return usuarioFacade; } @Autowired public void setUsuarioFacade(final UsuarioFacade usuarioFacade) { this.usuarioFacade = usuarioFacade; } @Test public void testUsuarioFacade() { assertNotNull(usuarioFacade); usuarioFacade.setUsrLogin("MI_LOGIN"); usuarioFacade.setUsrFullName("MI_FULL_NAME"); usuarioFacade.setUsrCargo("MI_CARGO"); usuarioFacade.save(); assertNotNull(usuarioFacade.getDelegate().getUsrId()); assertTrue(usuarioFacade.getDelegate().getUsrId() > 0); } } As i said before, everything works as expected when I ran test or install goal, but the surefire plugin does not work. I tried with every 2.4.x version of the surefire plugin. -- Cheers. Carlos Chávez. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
