使用 Websocket 配置通过 tomcat 部署 Spring Boot 应用程序

DP3

我有一个具有 Spring websocket 依赖关系的 Spring Boot 应用程序。该应用程序在我的 Intellij IDE 上运行良好,但在通过 TC 服务器部署时,它无法启动应用程序。

我确实有提供的 tomcat 服务器依赖项,并且应用程序扩展了 SpringBootServletInializer。

这是我的课

主类

package hello;

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) {
        SpringApplication.run(Application.class, args);
    }
}

问候控制器

package hello;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;

@Controller
@CrossOrigin
public class GreetingController {


    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        System.out.println("Received at controller level" + message.getName());
        //Thread.sleep(1000); // simulated delay
        return new Greeting("Hello, " + message.getName() + "!");
    }

}

Rest控制器之一

package hello;

import org.springframework.web.bind.annotation.*;

/**
 * Created on 4/19/2018.
 */
@RestController
public class NewRestTestController {
    @GetMapping("/test")
    public String testControl(){
        System.out.println("Request received");
        return "Rest Call tested successfully";
    }
}

Websocket 配置类

package hello;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
@EnableWebSocketMessageBroker()
@CrossOrigin(origins = "*")
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket").setAllowedOrigins("*").withSockJS();
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-messaging-stomp-websocket</artifactId>
    <version>0.1.0</version>

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

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>sockjs-client</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>stomp-websocket</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <packaging>war</packaging>
</project>

当我在 TC 服务器上部署应用程序时,服务器日志出现以下错误

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:167)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.nio.file.FileSystemNotFoundException: Provider "war" not installed
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 10 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.nio.file.FileSystemNotFoundException: Provider "war" not installed
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 31 more
Caused by: java.nio.file.FileSystemNotFoundException: Provider "war" not installed
        at java.nio.file.Paths.get(Paths.java:147)
        at org.webjars.urlprotocols.JarUrlProtocolHandler.isArchive(JarUrlProtocolHandler.java:88)
        at org.webjars.urlprotocols.JarUrlProtocolHandler.getSegments(JarUrlProtocolHandler.java:74)
        at org.webjars.urlprotocols.JarUrlProtocolHandler.getAssetPaths(JarUrlProtocolHandler.java:31)
        at org.webjars.WebJarAssetLocator.getAssetPaths(WebJarAssetLocator.java:91)
        at org.webjars.WebJarAssetLocator.getFullPathIndex(WebJarAssetLocator.java:121)
        at org.webjars.WebJarAssetLocator.<init>(WebJarAssetLocator.java:152)
        at org.springframework.web.servlet.resource.WebJarsResourceResolver.<init>(WebJarsResourceResolver.java:60)
        at org.springframework.web.servlet.config.annotation.ResourceChainRegistration.getResourceResolvers(ResourceChainRegistration.java:113)
        at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration.getRequestHandler(ResourceHandlerRegistration.java:161)
        at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getHandlerMapping(ResourceHandlerRegistry.java:156)
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:456)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$b8f3f684.CGLIB$resourceHandlerMapping$33(<generated>)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$b8f3f684$$FastClassBySpringCGLIB$$5ad853c4.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$b8f3f684.resourceHandlerMapping(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 32 more

Apr 27, 2018 11:15:38 AM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive [/export/appl/website/tcapp/Flex-Websockets/webapps/gs-messaging-stomp-websocket-0.1.0.war]
java.lang.IllegalStateException: 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.core.ContainerBase.addChildInternal(ContainerBase.java:756)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
DP3

我能够通过从应用程序的入门类中排除“WebMvcAutoConfiguration.class”来解决该问题。

@SpringBootApplication(exclude = WebMvcAutoConfiguration.class)

该代码现在可以在 websocket 上正常工作。我能够从 websocket 服务器接收响应。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将Spring Boot应用程序部署到Tomcat 8

来自分类Dev

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

来自分类Dev

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

来自分类Dev

在tomcat中部署后无法访问Spring Boot应用程序

来自分类Dev

将Spring Boot应用程序部署到独立的Tomcat中后无法正常工作

来自分类Dev

覆盖部署为 Tomcat 中的 WAR 的 spring-boot 应用程序的属性时的奇怪行为

来自分类Dev

Spring Boot 应用程序独立运行,但在 Tomcat 中部署时找不到类

来自分类Dev

如何使用Spring Boot将使用Postgresql的Spring应用程序部署到Heroku?

来自分类Dev

如何使用Spring Boot将使用Postgresql的Spring应用程序部署到Heroku?

来自分类Dev

无法使用 bitbucket 管道在 Heroku 中部署 spring-boot 应用程序

来自分类Dev

使用 RDS 在 AWS EB 上部署 Spring Boot 应用程序

来自分类Dev

使用 Gradle (Kotlin) 应用程序部署 Spring Boot - 找不到 jar

来自分类Dev

当部署到外部Tomcat / tc Server实例时,Spring Boot MVC应用程序返回HTTP 404

来自分类Dev

如何使用嵌入式tomcat会话集群设置Spring Boot应用程序?

来自分类Dev

在同一Spring Boot应用程序中使用Tomcat HTTP和Netty UDP

来自分类Dev

无法使用嵌入式 Tomcat 浏览到 Spring Boot 应用程序

来自分类Dev

将Spring Boot应用程序部署到AWS Beanstalk

来自分类Dev

将Spring Boot应用程序部署为Windows服务

来自分类Dev

无法将Spring Boot应用程序部署到Azure

来自分类Dev

无法部署Spring Boot应用程序

来自分类Dev

在Jenkins上部署Spring Boot应用程序

来自分类Dev

无法部署Spring Boot应用程序

来自分类Dev

Spring Boot应用程序部署到专用的码头实例

来自分类Dev

在Amazon上部署Spring Boot应用程序的最佳实践

来自分类Dev

Amazon Web Services - 部署 Spring Boot 应用程序

来自分类Dev

Spring Boot应用程序通过spring-boot-starter-actuator给出了“无法启动tomcat”异常

来自分类Dev

使用Tomcat从Eclipse部署的Web应用程序路径

来自分类Dev

如何使用maven和tomcat部署Web应用程序?

来自分类Dev

Tomcat不读取Spring-Boot应用程序属性

Related 相关文章

  1. 1

    将Spring Boot应用程序部署到Tomcat 8

  2. 2

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

  3. 3

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

  4. 4

    在tomcat中部署后无法访问Spring Boot应用程序

  5. 5

    将Spring Boot应用程序部署到独立的Tomcat中后无法正常工作

  6. 6

    覆盖部署为 Tomcat 中的 WAR 的 spring-boot 应用程序的属性时的奇怪行为

  7. 7

    Spring Boot 应用程序独立运行,但在 Tomcat 中部署时找不到类

  8. 8

    如何使用Spring Boot将使用Postgresql的Spring应用程序部署到Heroku?

  9. 9

    如何使用Spring Boot将使用Postgresql的Spring应用程序部署到Heroku?

  10. 10

    无法使用 bitbucket 管道在 Heroku 中部署 spring-boot 应用程序

  11. 11

    使用 RDS 在 AWS EB 上部署 Spring Boot 应用程序

  12. 12

    使用 Gradle (Kotlin) 应用程序部署 Spring Boot - 找不到 jar

  13. 13

    当部署到外部Tomcat / tc Server实例时,Spring Boot MVC应用程序返回HTTP 404

  14. 14

    如何使用嵌入式tomcat会话集群设置Spring Boot应用程序?

  15. 15

    在同一Spring Boot应用程序中使用Tomcat HTTP和Netty UDP

  16. 16

    无法使用嵌入式 Tomcat 浏览到 Spring Boot 应用程序

  17. 17

    将Spring Boot应用程序部署到AWS Beanstalk

  18. 18

    将Spring Boot应用程序部署为Windows服务

  19. 19

    无法将Spring Boot应用程序部署到Azure

  20. 20

    无法部署Spring Boot应用程序

  21. 21

    在Jenkins上部署Spring Boot应用程序

  22. 22

    无法部署Spring Boot应用程序

  23. 23

    Spring Boot应用程序部署到专用的码头实例

  24. 24

    在Amazon上部署Spring Boot应用程序的最佳实践

  25. 25

    Amazon Web Services - 部署 Spring Boot 应用程序

  26. 26

    Spring Boot应用程序通过spring-boot-starter-actuator给出了“无法启动tomcat”异常

  27. 27

    使用Tomcat从Eclipse部署的Web应用程序路径

  28. 28

    如何使用maven和tomcat部署Web应用程序?

  29. 29

    Tomcat不读取Spring-Boot应用程序属性

热门标签

归档