SpringCloud demo---eureka-server/eureka-client
阿新 • • 發佈:2019-02-19
app with mave 分享圖片 reat serve end str creation
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
SpringCloud demo---eureka-server/eureka-client