TongWeb支持Spring Boot、Spring Cloud说明

编程知识 更新时间:2023-04-05 03:13:16

问:TongWeb支持Spring Boot,Spring  Cloud吗?

答:主要看Spring Boot各个版本需要的JavaEE的web容器规范是多少,而Spring Cloud 构建于 Spring Boot 之上,也是看Spring Boot。

应用用Spring Boot2.x则用TongWeb7版本,下图为Spring官方对容器的要求。

应用用Spring Boot1.5.x则可用TongWeb6.1/7.0版本,下图为官方对容器的要求。

但是有些应用框架采用Spring Boot+Spring WebFlux方式,可以运行在非servlet容器上,采用netty线程池,这种使用方式也就不存在TongWeb替换tomcat、jetty的需求了,除非netty也列为必须替换的开源组件。

Spring 官网说明:

1.1.5. Servers

Spring WebFlux is supported on Tomcat, Jetty, Servlet 3.1+ containers, as well as on non-Servlet runtimes such as Netty and Undertow. All servers are adapted to a low-level, common API so that higher-level programming models can be supported across servers.

Spring WebFlux does not have built-in support to start or stop a server. However, it is easy to assemble an application from Spring configuration and WebFlux infrastructure and run it with a few lines of code.

Spring Boot has a WebFlux starter that automates these steps. By default, the starter uses Netty, but it is easy to switch to Tomcat, Jetty, or Undertow by changing your Maven or Gradle dependencies. Spring Boot defaults to Netty, because it is more widely used in the asynchronous, non-blocking space and lets a client and a server share resources.

Tomcat and Jetty can be used with both Spring MVC and WebFlux. Keep in mind, however, that the way they are used is very different. Spring MVC relies on Servlet blocking I/O and lets applications use the Servlet API directly if they need to. Spring WebFlux relies on Servlet 3.1 non-blocking I/O and uses the Servlet API behind a low-level adapter. It is not exposed for direct use.

For Undertow, Spring WebFlux uses Undertow APIs directly without the Servlet API.

Spring Boot、SpringCloud项目支持war包和jar包两种方式部署:

1. TongWeb6、7企业版/标准版支持以war包方式部署。

2. TongWeb7.0.E.x嵌入版支持以jar包方式部署。

当看到以下日志图标时表示Spring Boot启动。

注:在TongWeb上部署Spring Boot项目前,请先把应用lib下的tomcat*.jar相关jar清理干净,否则会看到各种在TongWeb中启动tomcat的错误。如下:

The Apache Tomcat Native library failed to load.The error reported was [java.lang.UnsatisfiedLinkError:Native Library /opt/tongweb/native/linux/aarch64/libtcnative-1.so already loaded in another classloader.

附:TongWeb7.0.E.x嵌入版打包示例

<project xmlns="http://maven.apache/POM/4.0.0" xmlns:xsi="http://www.w3/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache/POM/4.0.0 http://maven.apache/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>1.0.0</groupId>
  <artifactId>springboot-tw</artifactId>
  <version>1</version>
  <packaging>jar</packaging>
  <name>springboot-tw</name>
  <url>http://maven.apache</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
  </properties>
   <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.3.8.RELEASE</version>
		<relativePath/> 
	</parent>
  <dependencies> 
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
			<!-- 不用tomcat -->
			<exclusions>
              <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-tomcat</artifactId>
              </exclusion>
			</exclusions>
      </dependency>
	  <!--引入tongweb包 -->
	  <dependency>
           <groupId>com.tongweb.springboot</groupId>
           <artifactId>tongweb-spring-boot-starter</artifactId>
           <version>2.x.0.RELEASE</version>
      </dependency>
      <dependency>
           <groupId>com.tongweb</groupId>
           <artifactId>tongweb-embed</artifactId>
           <version>7.0.E.1</version>
      </dependency>     
      <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
	</dependency>  
  </dependencies>
  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.tong.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

更多推荐

TongWeb支持Spring Boot、Spring Cloud说明

本文发布于:2023-04-05 03:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/2adfaab9e9986b50bf07d462989b8338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   TongWeb   Cloud   Boot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 44456文章数
  • 14阅读数
  • 0评论数