@ResponseBody @RequestMapping(value = "/images/{path}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) @Cacheable("images") public byte[] image(@PathVariable path) throws IOException { InputStream in = servletContext.getResourceAsStream("images/"+path); return IOUtils.toByteArray(in); }
https://stackoverflow.com/questions/48742369/how-to-cache-image-files-in-spring-java-application/48744004
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html
可以使用springboot+redis等实现了nginx的一个本地缓存功能