我正在使用Spring MVC。在我的控制,我从MyClass的未找到Spring MVC文件异常
调用的函数MyClass{
public static void readFile(){
File file = new FileReader("myPath/myFile.txt");
...
}
public static void main(String[] args) {
readFile();//No problem
}
}
控制器:
@Controller
public class MyController{
@RequestMapping(value = "/url", method = RequestMethod.GET)
public String readFile(Locale locale, Model model) {
MyClass.readFile();//File not found exception
....
}
}
读数的时间我的主要测试()MyClass的作品,但是当我在服务器和访问运行该项目“/ url”,我得到这个:
java.io.FileNotFoundException: myPath/myFile.txt (The system cannot find the path specified)
如何在控制器中指定路径?
谢谢你的时间。
也许这可能对你有用https://stackoverflow.com/questions/36371748/spring-boot-access-static-resources-missing-scr-main-resources – lenach87