gpt4 book ai didi

spring - 为 spring boot 应用程序生成 war

转载 作者:行者123 更新时间:2023-11-28 22:35:21 25 4
gpt4 key购买 nike

我一直在关注 spring 提供的教程,但似乎无法理解为什么我的 .war 文件是空的。点击here查看/下载代码。最终目标是下载此文件,构建一个 .war 文件,然后将其部署到我的 tomcat 服务器。我已将以下内容添加到 build.gradle

应用插件:“war”

但这只会生成包含零类文件的 war 。

构建.gradle

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle
plugin:1.5.3.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]
}

最佳答案

对于教程代码,您需要做两件事:

  1. 打包war插件spring-boot ref :

    apply plugin: 'war'

    war {
    baseName = 'gs-spring-boot'
    version = '0.1.0'
    }
  2. 创建可部署的 war 文件 spring-boot ref :

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
    }

并指定所提供的 tomcat 依赖项:

dependencies {
// …
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
// …
}

这是我的 commit reference结果: result

关于spring - 为 spring boot 应用程序生成 war ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45134192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com