创建maven项目
导入依赖
java
<?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>
<groupId>org.example</groupId>
<artifactId>springcloudbook02</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>eurekaserver</module>
</modules>
<!--搭建聚合换环境-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.5.RELEASE</version>
</parent>
<properties>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
<mysql.version>8.0.29</mysql.version>
<mybatis.version>2.2.1</mybatis.version>
<pagehelper.version>1.2.10</pagehelper.version>
<lobmok.version>1.16.18</lobmok.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!--PageHelper-->
<!-- pagehelper 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lobmok.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
再创建优瑞卡服务
导入依赖
java
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
配置application.yml
java
server:
port: 8761
spring:
application:
name: eurekaserver
eureka:
client:
fetch-registry: false # 表示是否从Eureka Server获取注册的服务信息
register-with-eureka: false #表示是否将自己注册到Eureka Server
在eurikaserver下创建启动类
java
//开启eureka的服务
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApp {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApp.class,args);
}
}
启动测试,运行成功