springboot+VUE 使用thinJar方式部署:jar放在 /lib下,html放在 /static下

部署目录如下:

1.在WebMvcConfigurer 配置静态资源映射地址

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //允许访问静态资源,支持classpath:/static/ 及 jar的同级目录/static下
    String fileDir = "file:"+System.getProperties().getProperty("user.dir")+"/static/";
    registry.addResourceHandler("/**").addResourceLocations("classpath:/static/", fileDir);
}

2.配置 thymeleaf 映射路径

默认为 resources,改为 file:${user.dir}/static/

spring:
  thymeleaf:
    mode: HTML
    encoding: utf-8
    cache: false
    prefix: file:${user.dir}/static/

3. controller中写访问地址

/**
 * 进入页面 index.html -->  访问 localhost:8080/;  localhost:8080/index
 * @return
 */
@GetMapping({"/", "/index"})
public ModelAndView index() {
    return new ModelAndView("index.html");
}

4. 后端 jar分离部署,将springboot项目依赖第三方jar放在 /lib 下

我使用的是gradle,build.gradle 配置如下

plugins {
    id 'java'
}

group 'com.geline.cloud'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'cn.hutool:hutool-all:5.7.6'
    implementation 'org.springframework.boot:spring-boot-starter-logging'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-aop'
}

task clearJar(type: Delete) {
    delete "$buildDir\\libs\\lib"
}
task copyJar(type: Copy, dependsOn: 'clearJar') {
    from configurations.compileClasspath
    into "$buildDir\\libs\\lib"
}
bootJar.enabled = true
bootJar {
    excludes = ["*.jar"]
    dependsOn clearJar
    dependsOn copyJar
    manifest {
        attributes "Manifest-Version": 1.0, 'Class-Path': configurations.compileClasspath.files.collect { "lib/$it.name" }.join(' ')
    }
}

jar {
    enabled(true)
    from('src/main/java'){
        include '**/*.xml'
    }
}

publishing {
    repositories {
        maven {
            name = 'localRepo'
            url = "file://${buildDir}/repo"
        }
    }
    publications {
        myApp(MavenPublication) {
            from components.java
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星梦天河

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值