5. Spring Boot Jar Read Resource file
In the 2.2.2 section, it is stated that one of the features of Springboot is to run independently and embed the servlet container.
There are some problems with the Spring boot project running independently of development in jar mode, this chapter mainly describes the problem of reading static resource files.
Note:springboot packaging for jar boot does not unzip the jar, so the resource file cannot be read as a file path, but rather to fetch the file stream directly, and the ClassLoader used to read the file stream The loader of the ClassUtils.class.getClassLoader (), specifically related to the loader use of the springboot in jar mode, is interested in its own research.
Write the following code:
Make the project into a jar
Jar Boot
Access test:
< instance code >
Github:https://github.com/chunyuding/springboot-demo
Https://github.com/chunyuding/SpringBoot-Demo.git
Code Cloud: Https://gitee.com/dingchunyu/SpringBoot-Demo
Https://gitee.com/dingchunyu/SpringBoot-Demo.git
< recommended books >
Baidu Cloud: Http://pan.baidu.com/s/1qYA0Nxi
Spring Boot Reference Tutorial (vii) Spring boot jar Read Resource file