首页
/
行业洞察
/
正文
INDUSTRY INSIGHT · 深度
4、Eureka服务端安装
📅 2026/11/4 7:13:29
✍️ 爱科研究院
👁 阅读 3,247
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启动成功);}}
📌 标签:
工业官网
设计趋势
AI 建站
SEO
获取完整报告 →
RELATED ARTICLES
推荐阅读
2026/11/4 7:08:29
同城统一后台:外卖、跑腿和商城能不能在同一个入口里改
2026/11/4 7:08:29
国产半实物仿真平台选型指南:军工航天工程师信创适配建议
2026/11/4 7:08:29
硬件在环仿真测试系统选型建议:测试项目管理与HIL闭环功能说明
2026/11/4 8:03:32
微信小程序自动化测试:Minium框架实战指南
2026/11/4 8:03:32
港口车辆高精度定位与智能调度技术解析
2026/11/4 8:03:32
YouTube双语字幕技术解析与高效生成方案
2026/11/4 8:03:32
基于ADALM-Pluto的GPS L1 C/A信号生成与发射实践
2026/11/4 8:03:32
千笔AI:MBA学习场景的AIGC工具解析
2026/11/4 7:58:32
51单片机RFID入门:MFRC522寄存器级驱动与LED响应实战
2026/11/4 0:02:45
AI辅助技术栈评估:提升研发决策效率60%
2026/11/4 0:02:45
从生成Token到直接决策:Jev如何重塑AI Agent工程实践
2026/11/4 0:02:45
32G统一内存跑大模型:内存账、TPS实测与端云分流
2026/11/4 4:08:30
面向复杂光照与角度的宠物面部识别鲁棒性增强策略
2026/11/4 4:08:26
DRV8818PWPR与R7FA8M1AHECBD工业步进驱动实战指南
2026/11/4 4:08:23
STM32与DRV8818双极步进电机驱动方案:从选型到调试全流程解析
2026/11/4 4:08:30
面向复杂光照与角度的宠物面部识别鲁棒性增强策略
2026/11/4 4:08:26
DRV8818PWPR与R7FA8M1AHECBD工业步进驱动实战指南
2026/11/4 4:08:23
STM32与DRV8818双极步进电机驱动方案:从选型到调试全流程解析