<context:component-scan base-package="" />
如何扫描 jar 文件中的类。我的 Autowiring 类出现以下错误。
SEVERE [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.quartz.Scheduler com.path.controller.MyController.scheduler; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.quartz.Scheduler] 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)}
代码:
package com.path.controller;
import org.quartz.Scheduler;
@Controller
public class MyController{
@Autowired
Scheduler scheduler;
}
此调度程序位于 jar 文件 quartz-oracle-2.1.6.jar
内位于WEB-INF\lib
下。这个lib
位于 classes
之外部署包的文件夹。在 applicationcontext.xml
我有以下条目,
<context:component-scan base-package="com.path" />
最佳答案
当您使用 Eclipse 中的导出实用程序导出 jar 文件时,有一个名为“添加目录条目”的选项。勾选这个选项并导出jar文件,这样问题就解决了
关于java - 来自类外部的 jar 文件的 Autowiring 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44426634/