eskysky
Published on 2025-03-27 / 22 Visits
0

使用SpringBoot部署VUE项目刷新404解决办法

将VUE项目打包后放入SpringBoot项目的resources目录下,在浏览页面时刷新可能会出现404错误。

解决办法:新增配置类ErrorConfig

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

@Component
public class ErrorConfig implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
        registry.addErrorPages(error404Page);
    }
    
}