有这样一个需求,windows电脑,我是springboot项目,前端是vue,数据库是本地部署oracle,已部署安装完成,客户想要把这个作为单体项目,就是双击启动bat脚本即可浏览器上运行

详细步骤

  1. 在Vue项目中运行打包命令:

把前端的配置改成http://localhost:8080  其中如果要同局域网范围,需要把localhost改成本地(eg:192.168.123.1)电脑的ip,8080换成前端调用后端的端口

npm run build

     2.将生成的dist文件夹内容复制到SpringBoot的src/main/resources/static目录下

your-project/
├── frontend/          # Vue前端项目
└── backend/           # Spring Boot项目
    └── src/
        └── main/
            ├── java/
            └── resources/
                └── static/    # Vue打包文件将放在这里

确保backend/src/main/resources/static目录下有以下文件

static/
├── css/
├── js/
├── favicon.ico
└── index.html

     3.确保SpringBoot的pom.xml中包含

   <build>
       <plugins>
           <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
               <configuration>
                   <executable>true</executable>
               </configuration>
           </plugin>
       </plugins>
   </build>

        4.在Spring Boot中添加路由重定向接口

        【解释】这个接口是用来访问前端的,eg:后端的端口是9090,如果原来请求前端的url为:

http://localhost:8080/#/crew 则后续可以改为http://localhost:9090/#/crew  前端和后端公用一个端口

@Controller
public class FrontendController {
    @RequestMapping(value = "/{path:[^\\.]*}")
    public String redirect() {
        return "forward:/index.html";
    }
}

        5.使用Maven打包

mvn clean compile -U clean package -D maven.test.skip=true

        6.创建启动脚本

        Windows批处理文件(start.bat)     

@echo off
start javaw -jar your-application.jar
timeout /t 5
start http://localhost:9090/#/crew
exit

        访问以下URL验证:
                后端的端口为9090
                http://localhost:9090 (前端页面)
                http://localhost:9090/sysUser/1 (后端API)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值