【问题标题】:Spring boot app not loading when deploying war on tomcat 8在tomcat 8上部署战争时未加载Spring Boot应用程序
【发布时间】:2017-12-17 21:03:58
【问题描述】:

这是我的 build.gradle

plugins {
    id 'net.ltgt.apt' version '0.10'
    id 'org.springframework.boot' version '1.5.4.RELEASE'
    id 'com.github.johnrengelman.shadow' version '1.2.4'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'groovy'
apply plugin: 'jetty'
apply plugin: "net.ltgt.apt"
apply plugin: "org.springframework.boot"
bootRepackage.enabled=false
apply plugin: "com.github.johnrengelman.shadow"



def jdkVersion = 1.8

sourceCompatibility = jdkVersion
targetCompatibility = jdkVersion

jettyRun {
     httpPort = 8080
}

repositories {
    mavenCentral()
}

sourceSets.all { set ->
    def jarTask = task("${set.name}Jar", type: Jar) {
        baseName = baseName + "-$set.name"
        from set.output
    }

    artifacts {
        archives jarTask
    }
}

dependencies{


     def springpluginCore="1.2.0.RELEASE"
     def hibernateVersion="5.2.10.Final"
     def sqlServerVersion="6.1.7.jre8-preview"
     def springfoxSwaggerVersion="2.7.0"
     def springfoxSwaggerUiVersion="2.7.0"
     def jsonPathVersion="2.2.0"
     def jsonSchemaVersion="2.6.3"
     def junitVersion="4.9"
     def mapstructVersion="1.1.0.Final"
     def mapstructProcessorVersion="1.1.0.Final"

      // Infra dependency
     compile project(':pointin-infrastructure')

     //spring dependencies
     compile("org.springframework.boot:spring-boot-starter-hateoas")

     compile ("org.springframework.boot:spring-boot-starter-web")
     providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
  // compile('org.springframework.boot:spring-boot-starter-jetty')
     compile ("org.springframework.boot:spring-boot-starter-data-jpa")
     compile group: 'org.springframework.plugin', name: 'spring-plugin-core', version: "${springpluginCore}"

     //datasource dependencies
     compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: "${hibernateVersion}"
     compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version:"${sqlServerVersion}"
     compile ("org.springframework.boot:spring-boot-starter-data-mongodb")


     //swagger springfox dependencies
     compile group: 'io.springfox', name: 'springfox-swagger2', version: "${springfoxSwaggerVersion}"
     compile group: 'io.springfox', name: 'springfox-swagger-ui', version: "${springfoxSwaggerUiVersion}"

     //other dependencies
     compile group: 'com.jayway.jsonpath', name: 'json-path', version: "${jsonPathVersion}"
     compile group: 'org.mapstruct', name: 'mapstruct-jdk8', version: "${mapstructVersion}"
     apt "org.mapstruct:mapstruct-processor:${mapstructVersion}"    

     compile "com.fasterxml.jackson.module:jackson-module-jsonSchema:$jsonSchemaVersion"    
     compile "com.fasterxml.jackson.core:jackson-databind:"



     //test dependencies
      testCompile 'junit:junit:4.9'
}
war {
    from('src/main/resources') {
        include 'application.properties'
    }
}

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
            srcDir project(':pointin-infrastructure').file('src/main/java')
        }
        resources {
            srcDir 'src/main/resources'
        }
        output.classesDir   = 'build/classes/main/java'
        output.resourcesDir = 'build/classes/main/resources'
    }
    test {
        java {
            srcDir 'src/test/java'
        }
        resources {
            srcDir 'src/test/resources'
        }
        output.classesDir   = 'build/classes/test/java'
        output.resourcesDir = 'build/classes/test/resources'
    }

}

这是我的主文件

package com.dxc.pt.application.config;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

}

我正在尝试在 tomcat 8 上部署它,但它没有加载,因为我无法在战争中获取 lib 提供的文件夹。请不要说我对 gradle 很陌生

【问题讨论】:

  • 所有sourceSets { } 块都应该被删除,因为它要么是错误的,要么只指定了与默认值相同的值。这:srcDir project(':pointin-infrastructure').file('src/main/java') 不是你依赖另一个项目的方式,当你做 compile project(':pointin-infrastructure') 时你已经拥有了。
  • 我同意@nickb,我认为 sourceSets 主要是作为约定。我很好奇这个配置:bootRepackage.enabled=false,我们为什么需要它?
  • @chenrui bootreapackage.enabled 设置为 false,因为我不需要它,启用后它会给我一个异常“无法重命名依赖的 jar”
  • 这有什么更新吗?我觉得在这里贴一些错误日志会更好。

标签: tomcat spring-boot gradle build.gradle


【解决方案1】:

在我重新安装 java 后它最终开始工作。发现这是环境变量中设置的 JAVA_HOME 冲突的问题。 除了 eclipse 导出的战争不支持 gradle 并且在战争中产生战争而不是在战争中产生 gradle 产生的子项目的 jar

【讨论】:

    猜你喜欢
    • 2015-10-03
    • 2015-10-28
    • 1970-01-01
    • 2019-03-21
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 2016-03-23
    相关资源
    最近更新 更多