0

There are lot of Unitils based integration test classes in my application which uses @SpringApplicationContext (with different spring xmls from different modules) . In order to reduce the number of spring contexts being created, we planned to create a base test class and initialize the spring contexts only from this base class and make all the other tests to extend this base class.

base class:

com.org.module1.mypack;

@SpringApplicationContext({ "spring-module1.xml", "spring-module2.xml", "spring- module3.xml" }) public abstract class BaseTest{ ... }

child class before change:

com.org.module1.mypack.performance;

@SpringApplicationContext({ "spring-module4.xml" }) public class ChildTest extends BaseTest{ .. }

base class after change:

com.org.module1.mypack;

@SpringApplicationContext({ "spring-module1.xml", "spring-module2.xml", "spring- module3.xml", "spring-module4.xml" }) public abstract class BaseTest{ ... }

child class after change:

com.org.module1.mypack.performance;

//@SpringApplicationContext({ "spring-module4.xml" }) public class ChildTest extends BaseTest{ .. }

Now I get below error message and my context is not created: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.org.module5.prepare.MyBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=myBean)}

When the spring-module4.xml was in the child class, the context was created normally and all the tests executed as usual.

Note: all the spring xml files are in src/main/resources, except spring-module4.xml is in src/test/resources

EmeraldTablet
  • 812
  • 3
  • 12
  • 30
  • `NoSuchBeanDefinitionException` clearly exlpains that the parent class has no visibility of MyBean. Does that ring any bell for anybody? – EmeraldTablet Jan 23 '14 at 11:09

1 Answers1

0

By default annotations on classes are not inherited, unless they have @Inherited in their definition.

Eugene
  • 117,005
  • 15
  • 201
  • 306
  • That means you have to put @SpringApplicationContext on the child as well. But following the documentation: http://www.unitils.org/tutorial-spring.html, you can keep your new configuration as you have it. – Aurélien Thieriot Jan 23 '14 at 09:41
  • I tried adding `@SpringApplicationContext` to the child class as well... but still getting the same errors – EmeraldTablet Jan 23 '14 at 10:06