develog

[spring boot] static file 본문

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";
    }
    
}

 

'Dev > Spring Boot' 카테고리의 다른 글

Spring Boot jar, docker build  (0) 2020.08.06
[spring boot] static file read  (0) 2020.02.13
[spring boot] @SpringBootTest, MockMvc  (0) 2020.02.07
[H2] spring boot 에서 h2 memory db 사용하기  (0) 2019.12.13
[spring boot] jsp  (0) 2019.11.27
Comments