spring - Gradle 没有创建 Tomcat 可部署 war

标签 spring maven tomcat gradle war

我在使用 Gradle 4.8.1 构建 war 时遇到了问题。这是 build.gradle:

buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
    }
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}

apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

archivesBaseName = 'sample'

//war {
//    archiveName = 'sample.war'
//    group = 'my.group'
//    version = '2.0.0-SNAPSHOT'
//}

sourceCompatibility = 1.8

repositories {
    jcenter()
    maven { url "${nexusUrl}/content/groups/public" }
}

dependencies {

    // Spring
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.springframework.boot:spring-boot-starter-log4j2'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    compile 'org.springframework.boot:spring-boot-starter-web'
    testCompile 'org.springframework.boot:spring-boot-starter-test'

    // Lombok
    compile "org.projectlombok:lombok:1.18.0"

    // Data
    compile ('org.postgresql:postgresql') {
        exclude module: 'slf4j-simple'
    }

    // Http
    compile "org.apache.httpcomponents:httpclient:4.5.5"
}

configurations {
    all*.exclude module: 'spring-boot-starter-logging'
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "${nexusUrl}/content/groups/public/") {
                authentication(userName: nexusUsername, password: nexusPassword)
            }
            snapshotRepository(url: "${nexusUrl}/content/repositories/snapshots") {
                authentication(userName: nexusUsername, password: nexusPassword)
            }
            pom.version = '2.0.0-SNAPSHOT'
            pom.artifactId = 'sample'
            pom.groupId = 'my.group'
        }
    }
}

我还尝试删除“maven”插件、archivesBaseName 和 uploadArchive 任​​务,同时取消注释 war 任务,我得到了相同的结果。使用 uploadArchive 时,war 可以很好地部署到 nexus 服务器,我没有收到任何错误。将 war 部署到 tomcat 时(在这两种情况下)tomcat 7 和 8 没有抛出任何错误,我也没有收到来自 catalina 或项目的日志,尽管 war 任务中的 archiveName 没有正确重命名 war。我在其他两台机器/tomcat 实例上试过这个,结果相同。将其构建为 fat jar 或在 IntelliJ 中运行时,一切都按预期工作(包括日志记录)。

如有任何帮助或指导,我们将不胜感激。

最佳答案

听起来好像根本没有初始化 servlet。确保为 WAR 部署扩展 SpringBootServletInitializer。

关于spring - Gradle 没有创建 Tomcat 可部署 war ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51315213/

相关文章:

java - 如何将参数传递给验证Spring Webflow的方法?

java - 使用 MapReduce 在 couchbase 中动态 View

java - 为什么使用 Eclipse Webby 插件时 WebServlet 返回 404 错误?

Java 网络 : Currency Converter

spring - SpringBootServletInitializer在WAR部署中的重要性

java - 如何在Spring Boot中调用具有相同主题的两个KafkaListener?

java - AsynchronousJiraRestClientFactory 无法转换为 JiraRestClientFactory

java - 为什么 [appengine-api-1.0-sdk] 范围不是 "provided"?

java - intellij idea中tomcat 7中的参数

java - Tomcat 可以告诉 mod_jk 的负载均衡器在过载时使用另一个工作程序吗?如果是这样,如何?