java - 使用 Springboot Filewatcher 后,Spring boot @Autowire 和其他 DI 注释不起作用
问题描述
我正在使用 Springboot filewatcher 中的How to monitor folder/directory in spring? 我的观察者线程在我的应用程序启动时启动(在默认 tomcat 上部署),但我所有的 @Autowired 类的引用都变为空。我必须使用'new ClassName.methodName(); ' . 我的其他注释(如 @Value)也不起作用。
如此紧密耦合的原因是什么?我该如何解决这个问题?
可疑的代码片段:
@Override
public void onChange(Set<ChangedFiles> changeSet) {
for(ChangedFiles cfiles : changeSet) {
for(ChangedFile cfile: cfiles.getFiles()) {
if( (cfile.getType().equals(ChangedFile.Type.MODIFY)
|| cfile.getType().equals(ChangedFile.Type.ADD)
|| cfile.getType().equals(ChangedFile.Type.DELETE) )
&& !isLocked(cfile.getFile().toPath())) {
LOGGER.info("Operation type: " +cfile.getType()+ " on file: "+ cfile.getFile().getName() + " is detected");
obj = new TaskFlowController().initTasks();
}
解决方案
推荐阅读
- python - 将比赛与熊猫中的每个比赛行相关联
- scala - Scala 测试,如何从演员那里获取结果
- nodes - 在nodered中将值从数组发送到mqtt
- apache-spark - 将一年中的某一天转换为 day_month 格式
- python - 检查列表中的空白字符串
- javascript - 我如何在这个 JS 打字动画上添加比例、不透明度和 translateZ 效果,就像在anime.js 的第二个示例中一样
- flutter - 如果 TextSpan 包含不同的语言,则 TextSpan 的背景具有不同的高度
- javascript - 转换 JSON 对象列表
- html - 更改替换和排除多行 html 代码
- c - 如何拆分子目录名称?