I am adding some new components to an existing SpringBoot application, and am experiencing bean definition exceptions when starting the application.
All bean/service and other components are configured via annotations rather than via spring xml configurations (I am more familiar with xml based spring configurations). Unfortunately to explain my issue, I have to obfiscate a bit below rather than provide real code.
Within the application I have added a new factory component, call it FooSheetFactory:
package some.package;
@Component
public class FooSheetFactory {
private final List<FooSheet> fooSheetList;
@autowired
public FooSheetFactory(List<FooSheet> fooSheetList) {
this. fooSheetList = fooSheetList;
}
.
.
(other stuff)
.
}
This class uses a component called FooSheet:
package some.package;
@Component
public interface FooSheet {
public Foo getFoo(int param1, String param2);
}
The factory is instantiated elsewhere in the application in a manner like:
.
.
@Autowire
FooSheetFactory fsf;
.
.
When starting the SpringBoot app, I get the following error:
Error creating bean with name "FooSheetFactory " defined
in file [ ~path/target/classes/..../FooSheetFactory.class]: Unsatisfied dependency
expressed through constructor parameter 0; nested exception
is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of
type 'java.util.List<some.package.FooSheet>' available. Expected at least 1 bean which
qualifies as autowire candidate. Dependency annotations: {}
On the surface this instantiation to me is similar to how we are using spring elsewhere in the application. Both the class and the interface are in the same package and other classes in this package using similar annotations are not throwing errors at start-up. I would grateful for any insights into what my problem might be. Thank you.
Don't put @Component
annotation on interface, put it on implementation class. Your exception is complaining that it cannot find any implementation of your interface. You should have:
@Component
class FooSheetImpl implements FooSheet {
...
}