Technology Sharing

In traditional springboot projects, how to add custom static resource access paths to access static resources?

2024-07-11

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

How to configure the path in the browser to achieve personalized access path to index.html under the resource path
insert image description here

To configure a specific prefix to access static resources in a Spring Boot project, you canapplication.ymlConfigure the path mapping in the file. The following is an example configuration:

  1. Open yourapplication.ymlFiles, usually insrc/main/resourcesUnder contents.

  2. Add the following configuration:

spring:
  mvc:
    static-path-pattern: /your-prefix/**
  resources:
    static-locations: classpath:/static/