Springboot整合金蝶等中间件打包和部署

2 阅读4分钟

我正在参加「金石计划」

写在前面

在工作中,我们可能会遇到一些产品项目,要在不同的服务器部署,例如,在A项目部署,需要使用东方通中间件;在B项目部署,需要使用金蝶中间件;在C项目部署,则没有这样的要求,那就是用传统的tomcat中间件部署。

对于这些不同的中间件,那我们不应该是每次打包都去修改我们的pom.xml文件的吧?

如果每次都去改pom.xml文件,那就是太麻烦了,也有点鸡肋了!!!

请大家伙看到最后,这里提供一个比较好的解决方式!!!

image.png

金蝶整合说明

1.金蝶相关jar包依赖处理

解压下面的zip压缩包

  • AAMS-V10-embed.zip

将金蝶相关Jar包install安装到本地Maven仓库。

springboot1.x版本依赖安装:进入starter-1.5文件夹

mvn install:install-file -Dfile=aams-spring-boot-starter-all-1.5.20.RELEASE.jar -DgroupId=com.apusic -DartifactId=aams-spring-boot-starter-all -Dversion=1.5.20.RELEASE -Dpackaging=jar

springboot2.0-sprigboot2.4版本依赖安装:进入starter-2.1文件夹

mvn install:install-file -Dfile=aams-spring-boot-starter-all-2.1.7.RELEASE.jar -DgroupId=com.apusic -DartifactId=aams-spring-boot-starter-all -Dversion=2.1.7.RELEASE -Dpackaging=jar

sprigboot2中2.4以上版本依赖安装:进入starter-2.4文件夹

mvn install:install-file -Dfile=aams-spring-boot-starter-all-2.4.0.jar -DgroupId=com.apusic -DartifactId=aams-spring-boot-starter-all -Dversion=2.4.0 -Dpackaging=jar

注:

  1. websocket相关的jar包依赖,安装也参考上面mvn install方式即可。(项目用到websocket,才需要安装)

  2. 我们目前的框架用的是springboot2.3,所以这里我们安装金蝶2.1.7版本的依赖即可。

  3. 需要提前准备Maven构建管理工具,指定本地Maven仓库地址。

将金蝶相关Jar包deploy发布到公司nexus私服。

springboot2.0-sprigboot2.4版本依赖发布:进入starter-2.1文件夹

mvn deploy:deploy-file -Dfile=aams-spring-boot-starter-all-2.1.7.RELEASE.jar -DgroupId=com.apusic -DartifactId=aams-spring-boot-starter-all -Dversion=2.1.7.RELEASE -Dpackaging=jar -DrepositoryId="releases" -Durl="http://192.168.4.1:88/nexus/content/repositories/maven-releases"

sprigboot2中2.4以上版本依赖发布:进入starter-2.4文件夹

mvn deploy:deploy-file -Dfile=aams-spring-boot-starter-all-2.4.0.jar -DgroupId=com.apusic -DartifactId=aams-spring-boot-starter-all -Dversion=2.4.0 -Dpackaging=jar -DrepositoryId="releases" -Durl="http://192.168.4.1:88/nexus/content/repositories/maven-releases"

springboot1.x版本依赖发布:进入starter-1.5文件夹

mvn deploy:deploy-file -Dfile=aams-spring-boot-starter-all-1.5.20.RELEASE.jar -DgroupId=com.apusic -DartifactId=aams-spring-boot-starter-all -Dversion=1.5.20.RELEASE -Dpackaging=jar -DrepositoryId="releases" -Durl="http://192.168.4.1:88/nexus/content/repositories/maven-releases"

注:

1.AAMS相关的依赖已经发布到公司的nexus私服,能连上公司私服的,上面的安装和发布操作可以不用处理

2.发布依赖到公司nexus私服,maven相关的配置文件setting,需要配置nexus账号密码,这里不再说明。

2.springboot项目处理

  • pom.xml依赖处理
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!--排除springboot自带的tomcat依赖-->
    <exclusions>
        <exclusion>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <groupId>org.springframework.boot</groupId>
        </exclusion>
    </exclusions>
</dependency>
<!--增加aams的starter依赖-->
<dependency>
    <groupId>com.apusic</groupId>
    <artifactId>aams-spring-boot-starter-all</artifactId>
    <version>2.1.7.RELEASE</version>
</dependency>
  • 指定license文件路径
# 指定金蝶licpath文件路径
server.aas.license-path=/home/root/license.xml

注:

1.License 存放路径支持“本地磁盘路径”和“classpath路径”,

2.如果用到nacos配置中心的,可以放入到nacos的nacos-config-dev.properties配置里面。

3.相关参数配置修改

# tomcat 调优 
# 等待连接数
server.tomcat.accept-count=1000
# 最大连接数
server.tomcat.max-connections=1000
# 最大线程数量
server.tomcat.max-threads=1000
# 最小线程数
server.tomcat.min-spare-threads=10

改成

# tomcat 调优 
# 等待连接数
server.aas.accept-count=1000
# 最大连接数
server.aas.max-connections=1000
# 最大线程数量
server.aas.max-threads=1000
# 最小线程数
server.aas.min-spare-threads=10

4.mvn打包指定pom.xml

一般来说,一个项目只需有一个pom.xml文件即可。

但是有时候,可能需要整合金蝶东方通这些服务器中间件时,就需要将springboot内置的tomcat替换相应的中间件,这时虽然可以使用同一个pom.xml文件,但是每次打包都得改pom.xml,这样使用起来很不方便。

这时,我们可以为不同的中间件创建对应的pom.xml文件。

例如:金蝶,我们可以创建一个pomAas.xml文件;东方通,我们可以创建一个pomTw.xml文件;本地测试时编译项目使用的还是pom.xml文件。

当我们想打包金蝶相关的jar包时,可以使用下面的命令:

#指定pom文件打包:
mvn clean && mvn package -f pomAas.xml -Dmaven.test.skip=true

这样做的目的,是为了可以动态的切换打包的服务器中间件,也比较灵活。也能提交到svn中进行相关的记录。

pomAas.xml和原来的pom.xml,基本上是一样,只是加入了金蝶相关的依赖和去掉tomcat的依赖。


因为之前整合过东方通,感觉东方通在这方面做得比金蝶要好,因为东方通支持springboot3.0以上,而且还支持gateway网关的整合。

好了,以上就是我个人的实操了。可能有些不对,大家伙,轻点喷!!!

个人理解,可能也不够全面,班门弄斧了。

好了,今天就先到这里了!!!^_^

如果觉得有收获的,帮忙点赞、评论、收藏一下,再走呗!!!

image.png