Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How springboot accesses external resources through URL

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how springboot accesses external resources through URL". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how springboot accesses external resources through URL".

Springboot accesses external resources through URL

When you encounter this problem, there are only two ways to browse Baidu.

First kind

This method is out of date in springboot 2.1.8

The second kind

This method enables you to access the files in the specified directory through url, but using spring.resources.static-locations this configuration will overwrite the default static resource folder of SpringBoot, all the static resources of the project cannot be accessed, and the default value of spring.mvc.static-path-pattern is / * * without configuration.

The solution is to add a custom folder path to access in spring.resources.static-locations, which must start with file:, and add the default four static resource paths to access the project and custom static resources.

Custom static resource path is D:file/

Spring reported the error there because there is already a spring layer on it, which is added here to facilitate the demonstration.

Customize the files under the static resource folder

Download this picture of .jpg via url

At the same time, the project can also access

Springboot accesses the local file @ Configuration public class MyWebMvcConfigurer extends WebMvcConfigurationSupport {@ Override public void addResourceHandlers (ResourceHandlerRegistry registry) {/ / access the relative path registry.addResourceHandler ("/ assets/**") .addResourceLocations ("classpath:/assets/") through URL / / access absolute path access path and storage path can be customized. It is recommended to put the storage path in the configuration file registry.addResourceHandler ("/ img/**"). AddResourceLocations ("file:D:/img/"); super.addResourceHandlers (registry);}} localhost:8080/assets/ file name. Suffix Thank you for your reading, the above is the content of "how springboot accesses external resources through URL". After the study of this article, I believe you have a deeper understanding of how springboot accesses external resources through URL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 264

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report