【问题标题】:Eclipse Error: Websockets are currently only supported in TomcatEclipse 错误:Websockets 目前仅在 Tomcat 中受支持
【发布时间】:2014-06-23 16:40:07
【问题描述】:

我正在尝试在 web 应用程序中使用 tomcat,并希望使用 Spring 支持将 Tomcat servlet 容器嵌入为 HTTP 运行时,而不是像教程中那样部署到外部实例:http://spring.io/guides/gs/messaging-stomp-websocket/

但是,我收到此堆栈错误:

Caused by: java.lang.IllegalStateException: Websockets are currently only supported in Tomcat (found class org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory). 
at org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration$1.customize(WebSocketAutoConfiguration.java:74)
at org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor.postProcessBeforeInitialization(EmbeddedServletContainerCustomizerBeanPostProcessor.java:67)
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)
... 16 more

我不确定它现在是如何发生的,而不是在 Spring 示例中。这是我的 POM:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                      http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-messaging-stomp-websocket</artifactId>
<version>0.1.0</version>
<url>http://www.springframework.org</url>

<properties>
    <maven.test.failure.ignore>true</maven.test.failure.ignore>
    <spring.framework.version>3.0.6.RELEASE</spring.framework.version>
</properties>   

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.1.RELEASE</version>
    </parent>


<repositories>
    <repository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/libs-snapshot</url>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/libs-snapshot</url>
        <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
</pluginRepositories>
<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <version>1.1.1.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>log4j-over-slf4j</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>4.0.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-all</artifactId>
        <version>5.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.13.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.directory.studio</groupId>
        <artifactId>org.apache.commons.pool</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>apache-camel</artifactId>
        <version>2.13.1</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>jdk.tools</groupId>
        <artifactId>jdk.tools</artifactId>
        <scope>system</scope>
        <version>1.6</version>
        <systemPath>C:\Program Files\Java\jdk1.8.0_05\lib\tools.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>1.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-webapp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
    </dependency>
</dependencies>
    <build>
    <plugins>
        <plugin> 
            <artifactId>maven-compiler-plugin</artifactId> 
            <version>2.3.2</version> 
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我拥有 Spring 示例使用的所有依赖项。哪些因素会影响应用程序使用 Tomcat 的能力?

提前感谢您的帮助!

编辑:

这是 Application.class:

package hello;

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

@Component
@EnableAutoConfiguration
public class Application {


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

这是我的主要内容:

package com.example.integration;

import hello.*;

import org.apache.camel.ProducerTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class TestCamelSpring {

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("camelspring.xml");
    ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

    Application.main(args);
    System.out.println("Message Sending started");
    camelTemplate.sendBody("jms:queue:testQSource","Sample Message");
    System.out.println("Message sent");

}

}

【问题讨论】:

  • 你用的是什么版本的tomcat?
  • 我什至不确定。 Spring @EnableAutoConfiguration 注释应该自动启动一个 Tomcat 实例,但这似乎没有发生在这里。我已将带有注释的类和调用前一个类的类添加到我的问题中。

标签: eclipse spring maven tomcat


【解决方案1】:

你有一个码头依赖:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-webapp</artifactId>
</dependency>

因此,您实际上是在用 Jetty 替换嵌入式 Tomcat。如果你不想要 Jetty,就不要使用 Jetty 依赖。

【讨论】:

    猜你喜欢
    • 2015-04-05
    • 2021-09-09
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    相关资源
    最近更新 更多