Spring Boot Reference Tutorial (vii) Spring boot jar Read Resource file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.