我在使用Gradle 4.8.1进行战争时遇到了一个问题。这是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'
}
}
}
我还尝试在取消对war任务的注释的同时删除了'maven'插件,archivesBaseName和uploadArchive任务,我得到了相同的结果。当使用uploadArchive时,战争可以很好地部署到nexus服务器,并且我没有收到任何错误。将战争部署到tomcat时(在这两种情况下),tomcat 7和8都不会抛出错误,并且从catalina或项目中都不会收到日志,尽管war任务中的archiveName不能正确地重命名war。我已经在其他两个机器/ tomcat实例上尝试了相同的结果。当将其构建为胖子或在IntelliJ中运行时,一切都会按预期进行(包括日志记录)。
任何帮助或指导将不胜感激。
答案 0 :(得分:0)
听起来好像根本没有初始化servlet。确保扩展SpringBootServletInitializer以进行WAR部署。