Ich benutze Spring MVC. In meinem Controller rief ich eine Funktion von MyClassSpring MVC Datei nicht gefunden Ausnahme
MyClass{
public static void readFile(){
File file = new FileReader("myPath/myFile.txt");
...
}
public static void main(String[] args) {
readFile();//No problem
}
}
Controller:
@Controller
public class MyController{
@RequestMapping(value = "/url", method = RequestMethod.GET)
public String readFile(Locale locale, Model model) {
MyClass.readFile();//File not found exception
....
}
}
Das Lesen funktioniert, wenn ich es in der Hauptprüfung() von MyClass, aber wenn ich laufe das Projekt auf Server und Besuch "/ url", habe ich folgendes erhalten:
java.io.FileNotFoundException: myPath/myFile.txt (The system cannot find the path specified)
Wie lege ich den Pfad im Controller fest?
Vielen Dank für Ihre Zeit.
Vielleicht könnte dies für Sie nützlich sein https://stackoverflow.com/questions/36371748/spring-boot-access-static-resources-missing-scr-main-resources – lenach87