美文网首页SpringCloud
SpringCloud微服务实战——搭建企业级开发框架(四):集

SpringCloud微服务实战——搭建企业级开发框架(四):集

作者: 全栈程序猿 | 来源:发表于2020-11-09 23:02 被阅读0次

    1、在GitEgg工程的根目录,最上级父pom.xml文件中引入需要依赖的库及Maven插件,设置编码方式:

    <?xml version="1.0" encoding="UTF-8"?>
    <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>com.gitegg.cloud</groupId>
        <artifactId>GitEgg-Cloud</artifactId>
        <name>gitegg-cloud</name>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
    
        <modules>
            <module>gitegg-common</module>
            <module>gitegg-oauth</module>
            <module>gitegg-gateway</module>
            <module>gitegg-plugin</module>
            <module>gitegg-service</module>
            <module>gitegg-service-api</module>
        </modules>
    
        <properties>
            <!-- jdk版本1.8 -->
            <java.version>1.8</java.version>
            <!-- maven-compiler-plugin插件版本,Java代码编译 -->
            <maven.plugin.version>3.8.1</maven.plugin.version>
            <!-- maven编译时指定编码UTF-8 -->
            <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
            <!-- 项目统一字符集编码UTF-8 -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <!-- 项目统一字符集编码UTF-8 -->
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    
            <!-- GitEgg项目统一设置版本号 -->
            <gitegg.project.version>1.0-SNAPSHOT</gitegg.project.version>
            <!-- SpringBoot版本号 -->
            <spring.boot.version>2.3.3.RELEASE</spring.boot.version>
            <!-- SpringCloud版本号 -->
            <spring.cloud.version>Hoxton.SR8</spring.cloud.version>
        </properties>
    
        <dependencies>
            <!-- Lombok 通过简单注解消除冗长代码  -->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
        </dependencies>
    
        <dependencyManagement>
            <dependencies>
                <!-- spring boot工程的依赖库,无需继承spring-boot-starter-parent -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-dependencies</artifactId>
                    <version>${spring.boot.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <!-- spring cloud工程的依赖库 -->
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring.cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <build>
            <finalName>${project.name}</finalName>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                </resource>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
            </resources>
            <pluginManagement>
                <plugins>
                    <!-- 能够将Spring Boot应用打包为可执行的jar或war文件,然后以通常的方式运行Spring Boot应用 -->
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <version>${spring.boot.version}</version>
                        <configuration>
                            <fork>true</fork>
                            <finalName>${project.build.finalName}</finalName>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>repackage</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven.plugin.version}</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <encoding>UTF-8</encoding>
                        <compilerArgs>
                            <arg>-parameters</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    2、修改gitegg-service的pom.xml文件,引入需要的库:

    <?xml version="1.0" encoding="UTF-8"?>
    <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">
        <parent>
            <artifactId>GitEgg-Cloud</artifactId>
            <groupId>com.gitegg.cloud</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>gitegg-service</artifactId>
        <packaging>pom</packaging>
        <modules>
            <module>gitegg-service-base</module>
            <module>gitegg-service-bigdata</module>
            <module>gitegg-service-system</module>
        </modules>
    
        <dependencies>
            <!-- spring boot web核心包 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!-- spring boot 健康监控 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
        </dependencies>
        
    </project>
    

    3、在gitegg-service-system工程下新建GitEggSystemApplication主启动类:

    package com.gitegg.service.system;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /**
     * gitegg-system 启动类
     */
    @SpringBootApplication
    public class GitEggSystemApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(GitEggSystemApplication.class,args);
        }
    
    }
    
    

    4、在gitegg-service-system工程的resources目录下新建application.yml文件:

    server:
      port: 8001
    spring:
      application:
        name: gitegg-service-system
    

    5、在GitEggSystemApplication类上右键,Run 'GitEggSystemApplicat...' ,运行项目,可以看到最基础的SpringBoot项目启动成功:


    image.png

    本文源码在https://gitee.com/wmz1930/GitEgg 的chapter-04分支。

    GitEgg-Cloud是一款基于SpringCloud整合搭建的企业级微服务应用开发框架,开源项目地址:

    Gitee: https://gitee.com/wmz1930/GitEgg
    GitHub: https://github.com/wmz1930/GitEgg

    欢迎感兴趣的小伙伴Star支持一下。

    相关文章

      网友评论

        本文标题:SpringCloud微服务实战——搭建企业级开发框架(四):集

        本文链接:https://www.haomeiwen.com/subject/encrsktx.html