1.jar包引入。
Maven方式:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
或者gradle方式:
ext['springCloudVersion'] = 'Greenwich.M3'
dependencies {
implementation('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
2.application.yml配置:
server:
port: 8761
logging:
level:
org.springframework: info
org.springframework.security: debug
spring:
application:
name: eureka-server
http:
encoding:
force: true
servlet:
multipart:
max-file-size: 100MB # 最大文件大小
max-request-size: 100MB # 最大请求大小
jackson:
date-format: yyyy-MM-dd HH:mm:ss
eureka:
client:
register-with-eureka: false #是否注册自身到eureka服务器
fetch-registry: false
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/
3.Application启动类:
@SpringBootApplication
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
问题:
注册中心搭建完成后,启动项目,访问http://localhost:8761/ ,若显示Writable error page(即404错误):
解决办法:
SpringBoot与SpringCloud版本对应,对应图如下: