不能直接获取文件资源路径,但是可以通过流的方式读取资源 ClassPathResource resource = new ClassPathResource("static"+File.separator+"test.txt"); try (InputStream in = resource.getInputStream()){ //下载文件 return IOUtils.toString(in, StandardCharsets.UTF_8); } catch (IOException e) { e.printStackTrace(); return e.getMessage(); }