Dev/Spring Boot
[spring boot] static file
냐옴
2019. 11. 27. 17:07
file 경로
src/main/resources/static/readme11.txt |
controller
@Controller public class MyController { @Autowired private ResourceLoader resourceLoader; @RequestMapping(value = "/hello") public String hello() throws Exception { File file = null; ClassPathResource cpr = new ClassPathResource("static/readme11.txt"); System.out.println("11, " + cpr.exists() + ", " + cpr.getPath()); Resource resource = resourceLoader.getResource("classpath:static/readme11.txt"); file = resource.getFile(); System.out.println("22, " + file.exists() + ", " + file.getPath()); file = ResourceUtils.getFile("classpath:static/readme11.txt"); System.out.println("22, " + file.exists() + ", " + file.getPath()); return "hello"; } } |