SpringBoot+Vue项目打jar包

1,950 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。 ​

 一、打包Vue项目(开发工具webStorm)

vue搭建脚手架报错:rollbackFailedOptinal:verb npm-session

建议使用外网,不要用公司内网

添加依赖:npm install

​编辑

进行打包:npm run build

​编辑

之后会出现dist文件夹

​编辑

将dist下的文件放到idea中的static下

​编辑

添加静态资源访问的配置和依赖

<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

​编辑

package com.answer.testvue.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath/static/**").resourceChain(true);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {

        registry.addViewController("/").setViewName("forward:/index.html");


    }
}

因为我的spring boot是个空的项目,没有数据库连接什么的,所以需要跳过数据库自动配置

​编辑

同时也需要关闭这个,点击闪电按钮,这是为了防止之后打包失败

​编辑

之后install打包,然后在target下找到打好的jar包并启动

​编辑

启动成功

​编辑

参考链接:webStorm打包vue项目并且部署到服务器_滑稽的鼠标的博客-CSDN博客_webstorm项目打包