SpringCloud学习(三)创建demo注册到eureka
1.IDEA创建SpringBoot工程 demo1
先创建普通文件夹domain,用于放置demo1
再创建springboot项目
选择next,配置对应groupId及artifactId,不选择maven依赖,直接next
配置demo1存放位置,点击finish创建工程
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.liulin</groupId>
<artifactId>spring-cloud-demo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-cloud-demo1</name>
<description>SpringCloud聚合学习demo注册到eureka</description>
<parent>
<groupId>cn.liulin</groupId>
<artifactId>spring-cloud-integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<!--
eureka客户端maven依赖
-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--
eureka客户端启动web必需包
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
3.解决可能存在的报错信息
将import org.junit.jupiter.api.Test;
替换为import org.junit.Test;
4.添加注解及配置文件
在启动类上添加@EnableEurekaClient
将application.properties修改为application.yml
server:
port: 8762
spring:
application:
name: spring-cloud-demo1
eureka:
client:
service-url:
defaultZone: http://localhost:9999/eureka/
5.启动服务,访问eureka信息
http://127.0.0.1:9999/