1. 新建一个eureka server moduleprojectxmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.atguigu.springcloud/groupIdartifactIdcloud2020/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdcloud-eureka-server7001/artifactIdpackagingjar/packagingnamecloud-eureka-server7001/nameurlhttp://maven.apache.org/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdcom.atguigu.springcloud/groupIdartifactIdcloud-api-commons/artifactIdversion1.0-SNAPSHOT/version/dependency!-- 服务注册中心的服务端 eureka-server --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependencies/projectserver: port: 7001 # 单机版 eureka: instance: hostname: localhost #eureka服务端的实例名字 client: register-with-eureka: false #表示不向注册中心注册自己 fetch-registry: false #表示自己就是注册中心职责是维护服务实例并不需要去检索服务 service-url: #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/packagecom.atguigu.springcloud;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.cloud.netflix.eureka.server.EnableEurekaServer;// 设置为服务注册中心 EurekaServerSpringBootApplicationEnableEurekaServerpublicclassCloudEurekaServer7001Application{publicstaticvoidmain(String[]args){SpringApplication.run(CloudEurekaServer7001Application.class,args);System.out.println(EurekaServer启动成功);}}注意只是对外提供服务注册与发现不涉及任何的业务逻辑因此此module是没有业务逻辑代码的1.1 启动服务2. payment服务注册入eureka中pom.xml中引入eureka-client的jar包完整依赖如下projectxmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.atguigu.springcloud/groupIdartifactIdcloud2020/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdcloud-provider-payment8001/artifactIdpackagingjar/packagingnamecloud-provider-payment8001/nameurlhttp://maven.apache.org/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdcom.atguigu.springcloud/groupIdartifactIdcloud-api-commons/artifactIdversion1.0-SNAPSHOT/version/dependency!-- 服务注册中心的客户端端 eureka-client --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactId/dependencydependencygroupIdcom.alibaba/groupIdartifactIddruid-spring-boot-starter/artifactIdversion1.2.8/version/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-jdbc/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependencies/projectapplication.yml中引入单机的eureka的配置server: port: 8001 spring: application: name: cloud-payment-service datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/db2019?useUnicodetruecharacterEncodingutf-8useSSLfalse username: root password: root druid: initial-size: 5 max-active: 10 min-idle: 5 max-wait: 60000 test-while-idle: true validation-query: SELECT 1 test-on-borrow: false test-on-return: false time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 eureka: client: register-with-eureka: true #是否向注册中心注册自己 fetchRegistry: true #是否从注册中心抓取已有的注册信息 默认true集群必须设置为true service-url: # 设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址 defaultZone: http://localhost:7001/eureka #单机版 mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.atguigu.springcloud.entities启动类中加入注解packagecom.atguigu.springcloud;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.cloud.netflix.eureka.EnableEurekaClient;EnableEurekaClientSpringBootApplicationpublicclassCloudProviderPayment8001Application{publicstaticvoidmain(String[]args){SpringApplication.run(CloudProviderPayment8001Application.class,args);System.out.println(ProviderPayment8001Application 启动成功);}}order module注册进eurekaprojectxmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.atguigu.springcloud/groupIdartifactIdcloud2020/artifactIdversion1.0-SNAPSHOT/version/parentartifactIdcloud-consumer-order80/artifactIdpackagingjar/packagingnamecloud-consumer-order80/nameurlhttp://maven.apache.org/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!-- 服务注册中心的客户端端 eureka-client --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependencydependencygroupIdcom.atguigu.springcloud/groupIdartifactIdcloud-api-commons/artifactIdversion1.0-SNAPSHOT/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency/dependencies/projectserver: port: 80 spring: application: name: cloud-order-service eureka: client: register-with-eureka: true #是否向注册中心注册自己 fetchRegistry: true #是否从注册中心抓取已有的注册信息 默认true集群必须设置为true service-url: #设置与eureka server交互的地址查询服务和注册服务都需要依赖这个地址 defaultZone: http://localhost:7001/eureka #单机版packagecom.atguigu.springcloud;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.cloud.netflix.eureka.EnableEurekaClient;EnableEurekaClientSpringBootApplicationpublicclassCloudConsumerOrder80Application{publicstaticvoidmain(String[]args){SpringApplication.run(CloudConsumerOrder80Application.class,args);System.out.println(ConsumerOrder80Application启动成功);}}