Eureka单机版实战记录
1. Eureka 服务端
1.1 microservicecloud-eureka-7001
1.1.1 创建Module
1.1.2 父工程增加模块信息
1 2 3
| <modules> <module>microservicecloud-eureka-7001</module> </modules>
|
1.1.3 pom文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?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> <parent> <groupId>com.hellodev</groupId> <artifactId>atguigu-microservicecloud</artifactId> <version>0.0.1</version> </parent> <artifactId>microservicecloud-eureka-7001</artifactId> <version>0.0.1</version> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> </project>
|
1.1.4 yml文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| server: port: 7001 eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
|
1.1.5 Application启动类开启配置
1 2 3 4 5 6 7 8
| @SpringBootApplication
@EnableEurekaServer public class Eureka7001Application { public static void main(String[] args) { SpringApplication.run(Eureka7001Application.class, args); } }
|
1.1.6 启动验证
访问 : http://localhost:7001
2. Eureka 客户端
2.1 修改microservicecloud-provider-dept-8001
pom.xml中增加eureka客户端配置
1 2 3 4 5 6 7 8 9
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
|
2.2 yml修改
增加eureka配置
1 2 3 4 5
| eureka: client: service-url: defaultZone: http://localhost:7001/eureka
|
2.3 Application启动类开启配置
1 2 3 4 5 6 7 8
| @SpringBootApplication
@EnableEurekaClient public class ProviderDept8001Application { public static void main(String[] args) { SpringApplication.run(ProviderDept8001Application.class, args); } }
|
2.4 验证
先启动microservicecloud-eureka-7001,然后再启动microservicecloud-provider-dept-8001,界面出现provider的服务即成功.
3. actuator与注册微服务信息完善
3.1 主机名称:服务名称修改
当前问题: 显示的是ip地址,可读性差,交流不方便
修改microservicecloud-provider-dept-8001的yml配置文件
1 2 3 4 5 6 7 8
| eureka: client: service-url: defaultZone: http://localhost:7001/eureka instance: instance-id: microservicecloud-dept8001
|
修改之后
3.2 访问信息有IP信息提示
当前问题: 鼠标放在服务名称上,底部没有IP提示
修改microservicecloud-provider-dept-8001的yml配置文件
1 2 3 4 5 6 7 8 9 10
| eureka: client: service-url: defaultZone: http://localhost:7001/eureka instance: instance-id: microservicecloud-dept8001 prefer-ip-address: true
|
修改之后
3.3 微服务info内容详细信息
当前问题 : 超链接点击服务报告ErrorPage
修改microservicecloud-provider-dept-8001 POM
1 2 3 4 5
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
|
总的父工程microservicecloud修改pom.xml添加构建build信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <build> <finalName>microservicecloud</finalName> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <delimiters> <delimit>$</delimit> </delimiters> </configuration> </plugin> </plugins> </build>
|
修改microservicecloud-provider-dept-8001 YMl
1 2 3 4 5 6
| info: app.name: atguigu-microservicecloud company.name: www.atguigu.com build.artifactId: ${project.artifactId} build.version: ${project.version}
|
修改之后
资源获取
公众号回复 : Eureka单机实战 获取本节代码
公众号回复 : SpringCloud思维导图
Tips
欢迎收藏和转发,感谢你的支持!(๑•̀ㅂ•́)و✧
欢迎关注我:后端小哥,专注后端开发,希望和你一起进步!