I've got an abstract class:
@Component
public abstract class BaseReport {
public void export() {
...
}
And a bunch of classes that extend it, and override the export() method (or not).
@Component
public final class Report1 extends BaseReport
@Component
public final class Report2 extends BaseReport
Most of my tests autowire concrete classes that extend BaseReport, with no problems:
public class Report1Test extends BaseTest {
@Autowired
Report1 _report;
public class Report2Test extends BaseTest {
@Autowired
Report2 _report;
This works fine for autowiring of all classes that extend BaseReport. But I also need to autowire the abstract class itself, BaseReport, to test the export() method.
public class BaseReportTest extends BaseTest {
@Autowired
BaseReport _report;
When I try to run it I get the infamous:
No unique bean of type BaseReport is defined: expected single matching bean but found 2 [Report1, Report2].
I've tried using @Qualifier but the problem with @Qualifier is that (as I understand it) you use it to tell Spring which class -- that implements an Interface or extends an Abstract class - you wish to use. But that's not my case. I want to use the abstract class itself.
I also tried using @Resource, like this:
public class BaseReportTest extends BaseTest {
@Resource(name = "baseReport")
BaseReport _report;
Spring tells me there is no bean with this name. :(
How can I do this?
Cheers.