前言
众所周知, SpringBoot内置了tomcat, 可以直接执行jar包启动一个SpringBoot服务。因此VUE编译后的文件也可以部署再tomcat中提供访问, 这样对于轻量的应用无需再部署一个nginx。
SpringBoot 的静态内容
SpringBoot默认将
/static(或者/public或者/resources或者/META-INF/resources) 读取为静态内容。
其中static或者/template可以被用为欢迎页, 所以VUE编译后的静态文件可以放在static下提供访问。部署
为了避免静态路由与Rest Api冲突, 需再VUE中设置
publicPath: '/web'- 在
static文件夹中创建目录web, 将VUE编译后的dist中的内容复制至web目录下 - 将
/web增加在 token 校验忽略路径中 - 若VUE采用的是 history 模式, 需要增加未找到页面跳转配置。
@Component public class NotFoundPageConfig implements ErrorPageRegistrar { @Override public void registerErrorPages(ErrorPageRegistry registry) { ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/web/index.html"); registry.addErrorPages(error404Page); } } - 启动SpringBoot, 访问
http://localhost:[端口]/web即可
- 在
如何集成SpringBoot项目和VUE项目
欢迎您扫一扫上面的微信二维码,订阅我的公众号