我有一个想要添加ServletContextListener
接口的现有类:
@Service
public class MyService {
//...
}
@Component
public class MyController {
@Autowired
private MyService service;
}
这运行良好。但是一旦我添加public class MyService implements ServletContextListener
,我就会收到以下错误MyController
:
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private service. No qualifying bean of type [MyService] 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)}.
该应用程序在Tomcat
. 我的目标是@Override public void contextDestroyed()
在tomcat关闭时清理这个特定服务中的一些资源。
这里有什么问题?