Spring Cloud是在Spring Boot基础中构建的
1.首先是需要创建一个Spring boot的项目
2.配置pom.xml
主要是引入Eureka Server依赖
(1)引入spring cloud dependencies
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2023.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
(2)Eureka Server依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>${euraka.version}</version>
</dependency>
3.配置application.xml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
如果application.properties文件的话,可以新建一个application.xml文件
4.修改服务端JAVA代码
在项目上添加一个@EnableEurekaServer注解,声明该类为一个Eureka Server类。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class MicroserivceEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserivceEurekaServerApplication.class, args);
}
}
5.校验
启动Springboot项目,在浏览器访问localhost:8761/即可看到Eureka面板信息