SpringCloud demo---eureka-server/eureka-client

1.首先创建一个maven项目

  这个maven项目会包含springcloud相关的项目,目录结构如下图:

     

2.创建一个服务,也称为注册中心:eureka-service

  1.在该maven项目下新建一个module,eureka-service。即创建一个springboot项目,并添加相关依赖。步骤如下图:

    

    

  2.application.yml配置文件

    

server:
port: 8761
spring:
application:
name: eureka-server
security:
user:
name: admin
password: 123
eureka:
instance:
hostname: localhost
server:
enableSelfPreservation: false
eviction-interval-timer-in-ms: 1000
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

  3.pom.xml

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>

  4.在springboot启动类加上注解@EnableEurekaServer

package com.forezp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {

public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}

  5.启动项目。访问localhost:8761

猜你喜欢

转载自www.cnblogs.com/rainsakura/p/10403028.html