父工程依赖,注意springboot和springcloud的版本,不要起冲突
2.子工程4.0.0 cn.itcast.demo cloud-demo1.0 user-service order-service pom org.springframework.boot spring-boot-starter-parent2.3.9.RELEASE UTF-8 UTF-8 1.8 Hoxton.SR10 5.1.47 2.1.1 org.springframework.cloud spring-cloud-dependencies${spring-cloud.version} pom import mysql mysql-connector-java${mysql.version} org.mybatis.spring.boot mybatis-spring-boot-starter${mybatis.version} org.projectlombok lombok
需要引入的依赖及配置
pom.xml
org.springframework.cloud spring-cloud-starter-netflix-eureka-client3.1.0
application.yml,使用eureka必须要有的是服务名称application name和eureka:那些东西,
dafaultZone要与注册中心的地址对应,其它的子工程基本上也这么配,就是服务名称不同
spring:
datasource:
url: jdbc:mysql://localhost:3306/cloud_order?useSSL=false
username: root
password: x5
driver-class-name: com.mysql.jdbc.Driver
application:
name: orderservice
eureka:
client:
service-url: # eureka的地址信息
defaultZone: http://127.0.0.1:10086/eureka
3.注册中心
所需依赖:跟子工程引的差不多,区别一个是server,一个是client
org.springframework.cloud spring-cloud-starter-netflix-eureka-server3.1.0
主类
在@SpringBootApplication上面加个@EnableEurekaServer注解
package com.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
application.yml
server:
port: 10086 # 服务端口
spring:
application:
name: eurekaserver # eureka的服务名称
eureka:
client:
service-url: # eureka的地址信息
defaultZone: http://127.0.0.1:10086/eureka
效果:
点一下蓝色的路径就能直接跳转
注册中心页面
正好三个,eureka自己也算



