使用Tomcat部署多个SpringBoot项目减小内存

0

将多个SpringBoot部署到一个Tomcat项目中,单个进程减小内存占用。

  • 将所有依赖直接复制到Tomcatlib

配置如下:

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <env>dev</env>
                <nacos>192.168.8.83:8848</nacos>
                <nacosUser>nacos</nacosUser>
                <nacosPassword>nacos</nacosPassword>
                <package.type>jar</package.type>
                <pemc.jvm.arg></pemc.jvm.arg>
                <pemc.jvm.mem>-Xms1024m -Xmx2048m -XX:SurvivorRatio=2</pemc.jvm.mem>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <descriptors>
                                <descriptor>${pemc.path}/docs/assembly/package.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-maven-plugin</artifactId>
                            <configuration>
                                <!-- 注册中心乱码 -->
                                <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>jar</id>
            <properties>
                <env>jar</env>
                <nacos>192.168.8.83:8848</nacos>
                <nacosUser>nacos</nacosUser>
                <nacosPassword>nacos</nacosPassword>
                <package.type>jar</package.type>
                <pemc.jvm.arg></pemc.jvm.arg>
                <pemc.jvm.mem>-Xms1024m -Xmx2048m -XX:SurvivorRatio=2</pemc.jvm.mem>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <descriptors>
                                <descriptor>${pemc.path}/docs/assembly/package.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <!-- 打包jar配置 -->
                        <plugin>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-maven-plugin</artifactId>
                            <configuration>
                                <!-- 打包jar -->
                                <!--
                                <skip>true</skip>
                                -->
                                <!-- 注册中心乱码 -->
                                <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                                <!-- 生产排除依赖 -->
                                <!--
                                <excludes>
                                    <exclude>
                                        <groupId>org.springframework.boot</groupId>
                                        <artifactId>spring-boot-starter-tomcat</artifactId>
                                    </exclude>
                                </excludes>
                                <excludeGroupIds>
                                    io.swagger,
                                    io.springfox,
                                    org.mapstruct,
                                    org.projectlombok,
                                    io.swagger.core.v3,
                                    org.apache.tomcat.embed
                                </excludeGroupIds>
                                -->
                                <excludeGroupIds>
                                    io.swagger,
                                    io.springfox,
                                    org.mapstruct,
                                    org.projectlombok,
                                    io.swagger.core.v3
                                </excludeGroupIds>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>war</id>
            <properties>
                <env>war</env>
                <nacos>192.168.8.83:8848</nacos>
                <nacosUser>nacos</nacosUser>
                <nacosPassword>nacos</nacosPassword>
                <package.type>war</package.type>
                <pemc.jvm.arg></pemc.jvm.arg>
                <pemc.jvm.mem>-Xms1024m -Xmx2048m -XX:SurvivorRatio=2</pemc.jvm.mem>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <descriptors>
                                <descriptor>${pemc.path}/docs/assembly/package.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </plugin>
                </plugins>
                <pluginManagement>
                    <plugins>
                        <!-- 打包jar配置 -->
                        <plugin>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-maven-plugin</artifactId>
                            <configuration>
                                <!-- 打包jar -->
                                <skip>true</skip>
                                <!-- 注册中心乱码 -->
                                <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                            </configuration>
                        </plugin>
                        <!-- 打包war配置 -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-war-plugin</artifactId>
                            <configuration>
                                <packagingIncludes>META-INF/**,WEB-INF/classes/**,WEB-INF/lib/pemc-*.jar,WEB-INF/lib/taos-*.jar</packagingIncludes>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
            <dependencyManagement>
                <dependencies>
                    <dependency>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                        <optional>true</optional>
                    </dependency>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct</artifactId>
                        <version>${mapstruct.version}</version>
                        <optional>true</optional>
                    </dependency>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                        <optional>true</optional>
                    </dependency>
                    <dependency>
                        <groupId>io.springfox</groupId>
                        <artifactId>springfox-boot-starter</artifactId>
                        <version>${swagger.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct</artifactId>
                            </exclusion>
                        </exclusions>
                        <optional>true</optional>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                        <optional>true</optional>
                    </dependency>
                </dependencies>
            </dependencyManagement>
        </profile>
    </profiles>