先把Vue打包好的文件放到自己想要放的目录,这里我放在/home/web/resource下面

1.配置文件application.yml,配置访问的路径
web-config-resourcesHandler: /resource/**
2.配置Vue页面存放的路径
web-config-resourcesLocation: file:/home/web/resource/
3.编写WebConfig配置类,配置默认路由将根路径重定向到index.html
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Value("${web-config-resourcesHandler}")
private String[] resourcesHandler;
@Value("${web-config-resourcesLocation}")
private String[] resourcesLocation;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
for (int i = 0; i < resourcesHandler.length; i++) {
registry.addResourceHandler(resourcesHandler[i]).addResourceLocations(resourcesLocation[i]);
}
}
// 这里是将主页面设置输入IP:端口就可以直接访问
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// 先检查文件是否存在
File indexFile = new File("/home/web/resource/index.html");
if (indexFile.exists()) {
registry.addViewController("/")
.setViewName("redirect:/resource/index.html");
}
}
}
4.启动之后就可以直接通过127.0.0.1:端口,访问到主页面:/resource/index.html

被折叠的 条评论
为什么被折叠?



