【发布时间】:2017-08-10 22:57:31
【问题描述】:
我有包含接口的可运行 JAR A:
interface FooInterface {
void foo();
...
}
在 JAR A 中,我还有一个试图自动装配 FooInterface 实现的类:
class Other{
@Autowired
FooInterface fooInterfaceImplementation;
...
}
在其他项目 B 中,我将 jar A 作为外部库和 FooInterface 的实现:
@Component
class BarClass implements FooInterface {
void foo(){...}
...
}
我正在尝试使用以下命令运行可运行的 A JAR,其中包含 JAR B 中的类:
java -jar A.jar -cp B.jar
但它以以下异常结束:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ocado.cfc.optimisation.AlgorithmInterface' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:348)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:335)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
at com.ocado.cfc.optimisation.Executable.main(Executable.java:81)
是否可以以这种方式自动装配所需的 bean?
任何帮助高度赞赏。
【问题讨论】:
标签: java spring spring-boot jar autowired