IllegalStateException:在Java中使用文件函数时加载应用程序上下文失败
我使用这样的函数根据时间戳获取当前的最新文件:IllegalStateException:在Java中使用文件函数时加载应用程序上下文失败,java,spring,file,spring-mvc,illegalstateexception,Java,Spring,File,Spring Mvc,Illegalstateexception,我使用这样的函数根据时间戳获取当前的最新文件: File File=getFile(路径) 其中getFile()如下所示: private File getFile (String path) { File directory = new File(path); File[] files = directory.listFiles(File::isFile); long latestVersion = Long.MIN_VALUE; File latestFile = null; if (f
File File=getFile(路径)代码>
其中getFile()如下所示:
private File getFile (String path) {
File directory = new File(path);
File[] files = directory.listFiles(File::isFile);
long latestVersion = Long.MIN_VALUE;
File latestFile = null;
if (files!= null) {
for (File file : files) {
if (file.lastModified() > latestVersion) {
latestFile = file;
latestVersion = file.lastModified();
}
}
}
return latestFile;
}
在运行mvn clean install时,我遇到以下错误:
IllegalStateException:未能在同一模块的完全不同的测试类中加载应用程序上下文。
如果删除file方法,构建运行正常。这段代码肯定出了什么问题?
有人能帮忙吗
谢谢。请发布stacktrace?令人惊讶的是,这里没有堆栈跟踪,因为当我在单独的类中运行这段代码时,代码运行良好,并提供了文件。事实上,测试类也运行良好,并为我提供了文件名。