1.项目目录结构

网关
PublicGateWay:用户服务网关
AdminGateWay:管理员服务网关

服务:
CommonIntegration:通用集成服务,主要包含发送短信,邮件,上传文件等等,可被别的各个服务所调用。
IntegrationClient: CommonIntegration微服务的Feign client项目,可被被的微服务所包含,可直接使用来调用CommonIntegration的接口。
JobService:定时任务服务,一般不会被别的服务所调用。
UserService: 用户服务
OrderAccountService: 用户订单及账户服务。
ActivityService: 活动服务。
config: 各个服务的配置文件,方便部署。

2.注册中心

父项目pom文件
--------------------------------
<?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.xiayu</groupId>
    <artifactId>XiaYuApplication</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <parent> //父项目的父项目为springboot,版本为2.0.3.RELEASE
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/>
    </parent>


    <modules> //各个子模块
        <module>EurekaRigstryCenter</module>
        <module>PublicGateWay</module>
        <module>CommonIntegration</module>
        <module>UserService</module>
        <module>AdminGateWay</module>
        <module>OrderAccountService</module>
        <module>JobService</module>
        <module>ActivityService</module>
        <module>IntegrationClient</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <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>
        <dependencies>
            <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>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

EurekaRigstryCenter 注册中心 pom文件

<?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>XiaYuApplication</artifactId>
        <groupId>com.xiayu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>EurekaRigstryCenter</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <type>jar</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> //引入eureka-server依赖
        </dependency>
    </dependencies>
</project>

EurekaRigstryCenterApplication 启动类

package com.xiayu;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication //springboot注解
@EnableEurekaServer //eureka 注册中心
public class EurekaRigstryCenterApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaRigstryCenterApplication.class); //启动项目
    }
}

yml配置文件


spring:
  application:
    name: EurekaRigstryCenterApplication //服务名称
server:
  port: 8083 //服务端口

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false //自身作为注册中心,就不需要注册到注册中心
    fetchRegistry: false //表明自己是注册中心
    serviceUrl:
      defaultZone:  http://${eureka.instance.hostname}:${server.port}/eureka/ //注册中心地址,各个服务注册到注册中心,需要此url

访问注册中心(还没有服务注册到注册中心)

注册中心目录结构

03-05 22:29