码迷,mamicode.com
首页 > 编程语言 > 详细

tomcat源码springboot搭建的跑包含websocket的项目

时间:2020-06-30 22:21:29      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:ase   running   包含   localhost   startup   intern   async   sel   ber   

  之前我们用tomcat源码跑起来了,那么如何加入我们的应用呢?springboot内嵌了tomcat,怎么剥离?如果项目里有websocket配置,又有哪些注意项?好,我们看一下操作。

  1、要剥离springboot的内嵌tomcat,先修改pom.xml:

  1.1、新增

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.websocket</groupId>
            <artifactId>javax.websocket-api</artifactId>
            <scope>provided</scope>
        </dependency>

 

  1.2、修改:

     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

  如果原来的打jar包的话,记得改成war包:

<packaging>war</packaging>

  还有别忘记配置springboot的maven插件:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.wlf.DemoApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

 

  2、修改启动类:

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoApplication.class);
    }
}

 

  3、修改websocket配置类:

// WebSocketMessageBrokerConfigurer 是用来处理 STOMP协议 的
//@Configuration
//@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {


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

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

    //这个是处理基本的 websocket 连接的
//    @Bean
//    public ServerEndpointExporter serverEndpointExporter() {
//        return new ServerEndpointExporter();
//    }

}

 

  这样就可以跑maven打war包了。接下来我们把这个war包扔到tomcat源码的webapps目录下:

技术图片

 

 

 

  把tomcat跑起来,它会自动加压war包的。跑起来后我们跑一个试试:

技术图片

 

 

  日志如下:

六月 30, 2020 7:42:27 下午 org.apache.coyote.AbstractProtocol init
信息: å??å§?å??å??è®®å¤?ç??å?¨ ["http-nio-8080"]
六月 30, 2020 7:42:28 下午 org.apache.coyote.AbstractProtocol init
信息: å??å§?å??å??è®®å¤?ç??å?¨ ["ajp-nio-8009"]
六月 30, 2020 7:42:28 下午 org.apache.catalina.startup.Catalina load
信息: æ??å?¡å?¨å?¨[1,539]毫ç§?å??å??å§?å??
六月 30, 2020 7:42:28 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Catalina]
六月 30, 2020 7:42:28 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet engine: [Apache Tomcat/9.0.x-dev]
六月 30, 2020 7:42:28 下午 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive [E:\workspace\tomcat\webapps\subtitle-1.0-SNAPSHOT.war]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/workspace/tomcat/webapps/subtitle-1.0-SNAPSHOT/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/wulf/tomcat-build-libs/bnd-4.0.0/biz.aQute.bnd-4.0.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
六月 30, 2020 7:42:38 下午 org.apache.catalina.core.ApplicationContext log
信息: 2 Spring WebApplicationInitializers detected on classpath

  .   ____          _            __ _ _
 /\\ / ___‘_ __ _ _(_)_ __  __ _ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  ‘  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.6.RELEASE)

2020-06-30 19:42:40 [main] INFO  com.lxy.DemoApplication - Starting DemoApplication v1.0-SNAPSHOT on wulf00 with PID 60796 (E:\workspace\tomcat\webapps\subtitle-1.0-SNAPSHOT\WEB-INF\classes started by wulf in E:\workspace\tomcat) 
2020-06-30 19:42:40 [main] INFO  com.lxy.DemoApplication - No active profile set, falling back to default profiles: default 
2020-06-30 19:42:42 [main] INFO  o.a.c.c.C.[.[localhost].[/subtitle-1.0-SNAPSHOT] - Initializing Spring embedded WebApplicationContext 
2020-06-30 19:42:42 [main] INFO  org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1639 ms 
2020-06-30 19:42:43 [main] INFO  o.s.scheduling.concurrent.ThreadPoolTaskExecutor - Initializing ExecutorService ‘applicationTaskExecutor‘ 
2020-06-30 19:42:43 [main] INFO  com.lxy.DemoApplication - Started DemoApplication in 4.197 seconds (JVM running for 17.181) 
2020-06-30 19:42:43 [main] INFO  org.apache.jasper.servlet.TldScanner - è?³å°?æ??ä¸?个JAR被æ?«æ??ç?¨äº?TLDä½?å°?æ?ªå??å?«TLDã?? 为此记å½?å?¨å?¯ç?¨è°?è¯?æ?¥å¿?è®°å½?ï¼?以è?·å??å·²æ?«æ??ä½?æ?ªå?¨å?¶ä¸­æ?¾å?°TLDç??å®?æ?´JARå??表ã?? å?¨æ?«æ??æ??é?´è·³è¿?ä¸?é??è¦?ç??JARå?¯ä»¥ç¼©ç?­å?¯å?¨æ?¶é?´å??JSPç¼?è¯?æ?¶é?´ã?? 
2020-06-30 19:42:43 [main] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application archive [E:\workspace\tomcat\webapps\subtitle-1.0-SNAPSHOT.war] has finished in [15,423] ms 
2020-06-30 19:42:43 [main] INFO  org.apache.catalina.startup.HostConfig - æ??web åº?ç?¨ç¨?åº?é?¨ç½²å?°ç?®å½? [E:\workspace\tomcat\webapps\docs] 
2020-06-30 19:42:47 [main] INFO  org.apache.jasper.servlet.TldScanner - è?³å°?æ??ä¸?个JAR被æ?«æ??ç?¨äº?TLDä½?å°?æ?ªå??å?«TLDã?? 为此记å½?å?¨å?¯ç?¨è°?è¯?æ?¥å¿?è®°å½?ï¼?以è?·å??å·²æ?«æ??ä½?æ?ªå?¨å?¶ä¸­æ?¾å?°TLDç??å®?æ?´JARå??表ã?? å?¨æ?«æ??æ??é?´è·³è¿?ä¸?é??è¦?ç??JARå?¯ä»¥ç¼©ç?­å?¯å?¨æ?¶é?´å??JSPç¼?è¯?æ?¶é?´ã?? 
2020-06-30 19:42:47 [main] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory [E:\workspace\tomcat\webapps\docs] has finished in [3,673] ms 
2020-06-30 19:42:47 [main] INFO  org.apache.catalina.startup.HostConfig - æ??web åº?ç?¨ç¨?åº?é?¨ç½²å?°ç?®å½? [E:\workspace\tomcat\webapps\examples] 
2020-06-30 19:42:51 [main] INFO  org.apache.jasper.servlet.TldScanner - è?³å°?æ??ä¸?个JAR被æ?«æ??ç?¨äº?TLDä½?å°?æ?ªå??å?«TLDã?? 为此记å½?å?¨å?¯ç?¨è°?è¯?æ?¥å¿?è®°å½?ï¼?以è?·å??å·²æ?«æ??ä½?æ?ªå?¨å?¶ä¸­æ?¾å?°TLDç??å®?æ?´JARå??表ã?? å?¨æ?«æ??æ??é?´è·³è¿?ä¸?é??è¦?ç??JARå?¯ä»¥ç¼©ç?­å?¯å?¨æ?¶é?´å??JSPç¼?è¯?æ?¶é?´ã?? 
2020-06-30 19:42:51 [main] INFO  o.a.c.c.C.[Catalina].[localhost].[/examples] - ContextListener: contextInitialized() 
2020-06-30 19:42:51 [main] INFO  o.a.c.c.C.[Catalina].[localhost].[/examples] - SessionListener: contextInitialized() 
2020-06-30 19:42:51 [main] INFO  o.a.c.c.C.[Catalina].[localhost].[/examples] - ContextListener: attributeAdded(‘StockTicker‘, ‘async.Stockticker@69e9cbc2‘) 
2020-06-30 19:42:51 [main] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory [E:\workspace\tomcat\webapps\examples] has finished in [4,329] ms 
2020-06-30 19:42:51 [main] INFO  org.apache.catalina.startup.HostConfig - æ??web åº?ç?¨ç¨?åº?é?¨ç½²å?°ç?®å½? [E:\workspace\tomcat\webapps\host-manager] 
2020-06-30 19:42:55 [main] INFO  org.apache.jasper.servlet.TldScanner - è?³å°?æ??ä¸?个JAR被æ?«æ??ç?¨äº?TLDä½?å°?æ?ªå??å?«TLDã?? 为此记å½?å?¨å?¯ç?¨è°?è¯?æ?¥å¿?è®°å½?ï¼?以è?·å??å·²æ?«æ??ä½?æ?ªå?¨å?¶ä¸­æ?¾å?°TLDç??å®?æ?´JARå??表ã?? å?¨æ?«æ??æ??é?´è·³è¿?ä¸?é??è¦?ç??JARå?¯ä»¥ç¼©ç?­å?¯å?¨æ?¶é?´å??JSPç¼?è¯?æ?¶é?´ã?? 
2020-06-30 19:42:55 [main] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory [E:\workspace\tomcat\webapps\host-manager] has finished in [3,719] ms 
2020-06-30 19:42:55 [main] INFO  org.apache.catalina.startup.HostConfig - æ??web åº?ç?¨ç¨?åº?é?¨ç½²å?°ç?®å½? [E:\workspace\tomcat\webapps\manager] 
2020-06-30 19:42:59 [main] INFO  org.apache.jasper.servlet.TldScanner - è?³å°?æ??ä¸?个JAR被æ?«æ??ç?¨äº?TLDä½?å°?æ?ªå??å?«TLDã?? 为此记å½?å?¨å?¯ç?¨è°?è¯?æ?¥å¿?è®°å½?ï¼?以è?·å??å·²æ?«æ??ä½?æ?ªå?¨å?¶ä¸­æ?¾å?°TLDç??å®?æ?´JARå??表ã?? å?¨æ?«æ??æ??é?´è·³è¿?ä¸?é??è¦?ç??JARå?¯ä»¥ç¼©ç?­å?¯å?¨æ?¶é?´å??JSPç¼?è¯?æ?¶é?´ã?? 
2020-06-30 19:42:59 [main] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory [E:\workspace\tomcat\webapps\manager] has finished in [3,625] ms 
2020-06-30 19:42:59 [main] INFO  org.apache.catalina.startup.HostConfig - æ??web åº?ç?¨ç¨?åº?é?¨ç½²å?°ç?®å½? [E:\workspace\tomcat\webapps\ROOT] 
2020-06-30 19:43:02 [main] INFO  org.apache.jasper.servlet.TldScanner - è?³å°?æ??ä¸?个JAR被æ?«æ??ç?¨äº?TLDä½?å°?æ?ªå??å?«TLDã?? 为此记å½?å?¨å?¯ç?¨è°?è¯?æ?¥å¿?è®°å½?ï¼?以è?·å??å·²æ?«æ??ä½?æ?ªå?¨å?¶ä¸­æ?¾å?°TLDç??å®?æ?´JARå??表ã?? å?¨æ?«æ??æ??é?´è·³è¿?ä¸?é??è¦?ç??JARå?¯ä»¥ç¼©ç?­å?¯å?¨æ?¶é?´å??JSPç¼?è¯?æ?¶é?´ã?? 
2020-06-30 19:43:02 [main] INFO  org.apache.catalina.startup.HostConfig - Deployment of web application directory [E:\workspace\tomcat\webapps\ROOT] has finished in [3,576] ms 
2020-06-30 19:43:02 [main] INFO  org.apache.coyote.http11.Http11NioProtocol - å¼?å§?å??è®®å¤?ç??å?¥æ??["http-nio-8080"] 
2020-06-30 19:43:02 [main] INFO  org.apache.coyote.ajp.AjpNioProtocol - å¼?å§?å??è®®å¤?ç??å?¥æ??["ajp-nio-8009"] 
2020-06-30 19:43:02 [main] INFO  org.apache.catalina.startup.Catalina - Server startup in [34,471] milliseconds 
2020-06-30 19:46:11 [http-nio-8080-exec-5] INFO  o.a.c.c.C.[.[localhost].[/subtitle-1.0-SNAPSHOT] - Initializing Spring DispatcherServlet ‘dispatcherServlet‘ 
2020-06-30 19:46:11 [http-nio-8080-exec-5] INFO  org.springframework.web.servlet.DispatcherServlet - Initializing Servlet ‘dispatcherServlet‘ 
2020-06-30 19:46:11 [http-nio-8080-exec-5] INFO  org.springframework.web.servlet.DispatcherServlet - Completed initialization in 22 ms 
2020-06-30 19:46:12 [http-nio-8080-exec-5] INFO  com.lxy.controller.LiveController - liveSync info : LiveConfig(cutNumberForm=0, cutNumberTo=0, To=2, from=1, senseText=@, senseScreen=0, hotText=null, modalFilter=0, liveUrl=rtmp://58.200.131.2:1935/livetv/hunantv, timestamp=2000000) 

 

 

 

 

  

tomcat源码springboot搭建的跑包含websocket的项目

标签:ase   running   包含   localhost   startup   intern   async   sel   ber   

原文地址:https://www.cnblogs.com/wuxun1997/p/13216231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!