Spring Cloud切换内嵌Tomcat为宝兰德Application Server

替换Tomcat中间件

Tomcat是什么

Apache Tomcat (called “Tomcat” for short) is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies.[2] It provides a “pure Java” HTTP web server environment in which Java code can also run. Thus it is a Java web application server, although not a full JEE application server.

Tomcat is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation, released under the Apache License 2.0 license.

Spring Cloud剔除tomcat

        <!--集成springmvc框架 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <!-- 适配宝兰德,移除tomcat-->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
            <optional>true</optional>
        </dependency>

引入宝兰德Application Server

宝蓝德中间件的获取目前在官网是不能直接下载的,下载会提示你联系管理员;我是通过官网联系到客服,说明来意后,当地的销售人员联系我,并发送了相关中间件程序;
在这里插入图片描述

  • 百度网盘提取码:564x
  • 将需要的相关jar包install到本地的maven仓库,目前我只是用到了bes-lite-spring-boot-2.x-starter-9.5.5.003.jar和bes-websocket-9.5.5.003.jar
  • install命令
mvn install:install-file -Dfile=./bes-lite-spring-boot-2.x-starter-9.5.5.003.jar -DgroupId=com.bes.appserv-web -DartifactId=bes-lite-spring-boot-2.x-starter -Dversion=9.5.5.003 -Dpackaging=jar
mvn install:install-file -Dfile=./bes-websocket-9.5.5.003.jar -DgroupId=com.bes.appserv-web -DartifactId=bes-websocket -Dversion=9.5.5.003 -Dpackaging=jar
  • 在pom文件中引入打包的库文件
		<!-- 添加宝兰德依赖-->
		<dependency>
			<groupId>com.bes.appserv-web</groupId>
			<artifactId>bes-lite-spring-boot-2.x-starter</artifactId>
			<version>9.5.5.003</version>
		</dependency>
		<dependency>
			<groupId>com.bes.appserv-web</groupId>
			<artifactId>bes-websocket</artifactId>
			<version>9.5.5.003</version>
		</dependency>
  • 引入成功后,Tomcat相关的import需要做适当调整。

打包运行

目前项目就网关和系统模块两个模块,打包后正常启动

  • 网关微服务
    spring gateway目前是不依赖tomcat的,所以无需调整;
  • 系统微服务
    在这里插入图片描述
    日志输出这部分内容就说明宝兰德中间件正确启动了;

授权

宝蓝德官方给出的授权方案一共有6种:

  1. 通过系统属性指定License文件所在目录
  2. 通过系统属性指定License文本数据
  3. 通过环境变量指定License文件所在目录
  4. 通过环境变量指定License文本数据
  5. 指定BES根目录
  6. 替换jar包中的License文件

授权方案6是将介质文件bes‑lite‑spring‑boot‑2.x‑starter.jar解压到目录bes‑lite‑starter中

jar -xvf bes‑lite‑spring‑boot‑2.x‑starter.jar -C ./bes‑lite‑starter/

使用正式版的bes.lic.txt替换掉bes‑lite‑starter目录中的bes.lic.txt文件,进入bes‑lite‑starter目录执行
以下打包命令:

jar -cvf0m bes-lite-spring-boot-2.x-starter.jar META-INF/MANIFEST.MF *

注:jar命令选项0表示不压缩。

gateway为什么不依赖Tomcat

Spring Boot 启动内嵌 Tomcat 的过程可以分为以下几个步骤: 1. 配置 Spring Boot 应用程序的 pom.xml 文件,添加以下依赖项: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 2. 创建一个 Spring Boot 应用程序类,并在其 main 方法中调用 SpringApplication.run 方法,如下所示: ``` @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } } ``` 3. 在应用程序配置文件 application.properties 或 application.yml 中配置 Tomcat 服务器相关的属性,例如端口号、上下文路径等,如下所示: ``` # application.properties server.port=8080 server.servlet.context-path=/myapp ``` ``` # application.yml server: port: 8080 servlet: context-path: /myapp ``` 4. 使用 Spring Boot 提供的嵌入式 Tomcat 作为 Web 服务器。Spring Boot 会根据应用程序的配置自动配置 Tomcat 服务器,创建 TomcatEmbeddedServletContainerFactory 对象,并将其注入到 Spring 容器中。 5. 在应用程序启动过程中,Spring Boot 会扫描应用程序中所有的 @Controller、@RestController、@RequestMapping 等注解,并将其注册到 Tomcat 服务器中。 6. 当应用程序收到请求时,Tomcat 服务器会将请求转发给对应的 Controller 方法,Controller 方法会处理请求并返回响应,Tomcat 服务器将响应发送给客户端。 以上就是 Spring Boot 启动内嵌 Tomcat 的过程。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值