0

我正在尝试在 Eclipse 中使用 gradle 运行 Spring Boot 应用程序。它为 bootRun 提供了一个例外。我尝试了几乎所有与此异常相关的组合。我试图在 spring boot 应用程序中排除冲突的 tomcat jar。然而它不起作用。

例外:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
11:41:28.968 [QUIET] [system.out]   at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
11:41:28.968 [QUIET] [system.out]   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
11:41:28.969 [QUIET] [system.out]   at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
11:41:28.969 [QUIET] [system.out]   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
11:41:28.970 [QUIET] [system.out]   at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
11:41:28.970 [QUIET] [system.out]   at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
11:41:28.970 [QUIET] [system.out]   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
11:41:28.970 [QUIET] [system.out]   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
11:41:28.970 [QUIET] [system.out]   at com.att.it.wpwcm.main.Application.main(Application.java:15)
11:41:28.970 [QUIET] [system.out]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:41:28.970 [QUIET] [system.out]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
11:41:28.971 [QUIET] [system.out]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11:41:28.971 [QUIET] [system.out]   at java.lang.reflect.Method.invoke(Method.java:498)
11:41:28.971 [QUIET] [system.out]   at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
11:41:28.971 [QUIET] [system.out] Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;
11:41:28.971 [QUIET] [system.out]   at io.undertow.websockets.jsr.Bootstrap.handleDeployment(Bootstrap.java:93)
11:41:28.971 [QUIET] [system.out]   at io.undertow.servlet.core.DeploymentManagerImpl.handleExtensions(DeploymentManagerImpl.java:252)
11:41:28.971 [QUIET] [system.out]   at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:152)
11:41:28.972 [QUIET] [system.out]   at org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory.createDeploymentManager(UndertowEmbeddedServletContainerFactory.java:394)
11:41:28.972 [QUIET] [system.out]   at org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory.getEmbeddedServletContainer(UndertowEmbeddedServletContainerFactory.java:228)
11:41:28.972 [QUIET] [system.out]   at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
11:41:28.972 [QUIET] [system.out]   at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
11:41:28.972 [QUIET] [system.out]   ... 13 common frames omitted
11:41:28.973 [QUIET] [system.out] 

我的 build.gradle 文件:

    buildscript {
    repositories {
        maven { url "https://repo.spring.io/libs-release" }
        maven { url "https://repo1.maven.org/maven2/" }
        mavenLocal()
        mavenCentral() 
        jcenter()  
        maven { url "http://oss.jfrog.org/artifactory/oss-snapshot-local/" }            
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE")          
        classpath("org.springframework:spring-web:3.0.4.RELEASE")   
        classpath("org.springframework:spring-context-support:3.2.0.RELEASE")  
        classpath("org.springframework:spring-webmvc:4.1.6.RELEASE")
        classpath("io.springfox:springfox-swagger2:2.5.0")        
    }

}

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

jar {
    baseName = 'wpwcm-batch-db'
    version =  '0.1.0'
}

bootRepackage {
    mainClass = 'com.att.it.wpwcm.main.Application'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-batch")
    compile("org.hsqldb:hsqldb")
    compile 'javax.mail:mail:1.4.1'
    compile 'org.springframework:spring-context'
    compile group: 'org.springframework', name: 'spring-context-support', version: '3.2.0.RELEASE'
    compile group: 'org.springframework', name: 'spring-web', version: '4.3.4.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version: '4.1.6.RELEASE'
    compile("org.springframework.boot:spring-boot-starter-web") 
    compile("org.springframework.boot:spring-boot-starter-undertow:1.2.3.RELEASE") 
    compile("org.springframework.boot:spring-boot-starter-activemq")
    compile group: 'com.google.code.gson', name: 'gson', version: '1.7.2'
    compile("io.springfox:springfox-swagger2:2.5.0")
    compile("io.springfox:springfox-swagger-ui:2.0.2")   
    testCompile("junit:junit")
    //compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.8'
    compile("org.slf4j:jul-to-slf4j")  
    compile("org.springframework.boot:spring-boot-starter-logging")
    //compile("org.springframework.boot:spring-boot-starter-actuator")
    compile fileTree(dir: 'libs', include: ['*.jar'])    
    compile("org.springframework.boot:spring-boot-devtools")

}
4

1 回答 1

0

尝试以下命令:

./gradlew clean

这个命令:

./gradlew build

它应该修复 bootRun 异常。

于 2018-04-12T17:03:08.063 回答