LifecycleException将Spring Boot WebSocket示例部署到Tomcat中

LifecycleException将Spring Boot WebSocket示例部署到Tomcat中,tomcat,spring-boot,Tomcat,Spring Boot,在成功运行完之后,我非常希望将此应用程序构建为WAR,并将其部署到Tomcat中。我已经尽了最大的努力修改项目,以按照以下步骤构建WAR文件,但是当我部署生成的WAR时,Tomcat抛出了一个异常 我正在使用STS3.4.0和Gradle1.10进行开发,之前在Eclipse中使用Maven进行构建时未能成功部署,所以我改用了STS3.4.0。Gradle报告了一个成功构建的WAR文件,但当我尝试将其部署到Tomcat中时,引发了以下异常: 09-Feb-2014 17:30:27.537 SE

在成功运行完之后,我非常希望将此应用程序构建为WAR,并将其部署到Tomcat中。我已经尽了最大的努力修改项目,以按照以下步骤构建WAR文件,但是当我部署生成的WAR时,Tomcat抛出了一个异常

我正在使用STS3.4.0和Gradle1.10进行开发,之前在Eclipse中使用Maven进行构建时未能成功部署,所以我改用了STS3.4.0。Gradle报告了一个成功构建的WAR文件,但当我尝试将其部署到Tomcat中时,引发了以下异常:

09-Feb-2014 17:30:27.537 SEVERE [localhost-startStop-3] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/gs-messaging-stomp-websocket-0.1.0]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:699)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1763)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfiguration$TomcatWebSocketConfiguration.class]: Initialization of bean failed; nested exception is java.lang.ArrayStoreException: org.apache.catalina.valves.RemoteIpValve
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:658)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:355)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:129)
    at org.springframework.boot.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:90)
    at org.springframework.boot.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:53)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:181)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5237)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: java.lang.ArrayStoreException: org.apache.catalina.valves.RemoteIpValve
    at org.springframework.boot.autoconfigure.web.ServerProperties$Tomcat.customizeTomcat(ServerProperties.java:212)
    at org.springframework.boot.autoconfigure.web.ServerProperties.customize(ServerProperties.java:117)
    at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:68)
    at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:54)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    ... 27 more
我正在Windows 8.1 64位上运行Tomcat 8.0.0-RC10。我相信有关的申请文件如下:

Application.java:

套餐你好

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
HelloWebXml.java代替实际的web.xml:

package hello;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.SpringBootServletInitializer;

public class HelloWebXml extends SpringBootServletInitializer {

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

}
最后,build.gradle:

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC1")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'gs-messaging-stomp-websocket'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT")
    compile("org.springframework.boot:spring-boot-starter-websocket:0.5.0.BUILD-SNAPSHOT")
    compile("org.springframework:spring-messaging:4.0.0.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit:4.11")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.10'
}
configurations {
    provided
}

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}

eclipse.classpath.plusConfigurations += configurations.provided 

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT") {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile("org.springframework.boot:spring-boot-starter-websocket:0.5.0.BUILD-SNAPSHOT") {
        exclude module: 'spring-boot-starter-tomcat'
    }   

    provided group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '0.5.0.BUILD-SNAPSHOT'

    compile("org.springframework:spring-messaging:4.0.0.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit:4.11")
}
我必须说,我发现问题似乎出在tomcatEmbeddedServletContainerFactory身上,这很讽刺,而且有点令人沮丧。因此,我认为一个特性的唯一目的是允许应用程序在servlet容器之外运行,而我对这个特性完全不感兴趣,它阻止我将应用程序正确部署到servlet容器中


非常感谢您提供的所有帮助。

您需要立即提供嵌入式tomcat依赖项。您在编译配置中有spring boot starter tomcat,可以通过spring boot starter web进行转换。如果你真的不需要嵌入式服务器,你可以完全删除它。Gradle有标准的习惯用法来排除可传递的依赖项,并在不同的配置中添加它们,我相信。

您需要立即提供嵌入式tomcat依赖项。您在编译配置中有spring boot starter tomcat,通过spring boot starter web可传递。如果你真的不需要嵌入式服务器,你可以完全删除它。Gradle有标准的习惯用法来排除可传递的依赖项,并在不同的配置中添加它们,我相信。

在Syer先生的回答的帮助下,对不起,我试图升级投票,但我对这个论坛太陌生了,还有关于如何将资源标记为“已提供”的信息,我终于得到了这座建筑作为一场战争,我可以在Tomcat中成功部署它

经过一点实验,似乎需要对my build.gradle进行以下更改:

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC1")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'gs-messaging-stomp-websocket'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT")
    compile("org.springframework.boot:spring-boot-starter-websocket:0.5.0.BUILD-SNAPSHOT")
    compile("org.springframework:spring-messaging:4.0.0.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit:4.11")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.10'
}
configurations {
    provided
}

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}

eclipse.classpath.plusConfigurations += configurations.provided 

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT") {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile("org.springframework.boot:spring-boot-starter-websocket:0.5.0.BUILD-SNAPSHOT") {
        exclude module: 'spring-boot-starter-tomcat'
    }   

    provided group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '0.5.0.BUILD-SNAPSHOT'

    compile("org.springframework:spring-messaging:4.0.0.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit:4.11")
}
当我仅应用“排除模块”更改时,我遇到了一个编译时错误,抱怨没有找到javax.servlet.ServletException的类文件,这让我很困惑,因为我认为这是我的Java 7 JDK的一部分


当我只应用了“提供的组”更改时,它实际上并没有从我的war中删除spring boot starter tomcat jars。

在Syer先生的回答的帮助下,对不起,我试图升级投票,但我对这个论坛太陌生了,还有关于如何将资源标记为“提供”的信息,我终于得到了这座建筑作为一场战争,我可以在Tomcat中成功部署它

经过一点实验,似乎需要对my build.gradle进行以下更改:

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC1")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'gs-messaging-stomp-websocket'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT")
    compile("org.springframework.boot:spring-boot-starter-websocket:0.5.0.BUILD-SNAPSHOT")
    compile("org.springframework:spring-messaging:4.0.0.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit:4.11")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.10'
}
configurations {
    provided
}

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}

eclipse.classpath.plusConfigurations += configurations.provided 

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT") {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile("org.springframework.boot:spring-boot-starter-websocket:0.5.0.BUILD-SNAPSHOT") {
        exclude module: 'spring-boot-starter-tomcat'
    }   

    provided group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '0.5.0.BUILD-SNAPSHOT'

    compile("org.springframework:spring-messaging:4.0.0.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("junit:junit:4.11")
}
当我仅应用“排除模块”更改时,我遇到了一个编译时错误,抱怨没有找到javax.servlet.ServletException的类文件,这让我很困惑,因为我认为这是我的Java 7 JDK的一部分

当我只应用“提供的组”更改时,它实际上并没有从我的war中删除spring boot starter tomcat JAR