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

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

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

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

但是有些应用框架采用Spring Boot+Spring WebFlux方式,可以运行在非servlet容器上,如:Spring Cloud Gateway, 仅可用TongWeb嵌入版。

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、8企业版/标准版支持以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.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>1.0.0</groupId>
  <artifactId>springboot-tw</artifactId>
  <version>1</version>
  <packaging>jar</packaging>
  <name>springboot-tw</name>
  <url>http://maven.apache.org</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>

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐