我是用的版本是
Spring-Boot: 2.0.1 Re
Spring-Cloud : Greenwich.RC2
配置文件 application.yml
文件中主要配置 Eureka 、Config 、 Zuul 、 Security-Base-Auth
server:
port: 3000
spring:
application:
name: lostfound-config-server
###-----------------------------------------------eureka
eureka:
instance:
hostname: localhost
appname: ${spring.application.name}
instance-id: ${eureka.instance.hostname}:${server.port}
### spring cloud bus + spring boot actuator 用于向服务发送消息
index: 9012
### 客户端心跳时间和剔除时间
lease-renewal-interval-in-seconds: 1
lease-expiration-duration-in-seconds: 5
client:
register-with-eureka: false
### 是否拉取各服务列表信息
fetch-registry: false
service-url:
defaultZone: http://admin:admin@localhost:8000/eureka/
### 服务端开发模式下关闭自我保护机制
server:
enable-self-preservation: false
eviction-interval-timer-in-ms: 5000
###-----------------------------------------------spring cloud config
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/YardStrong/spring-cloud-lostfound-config
username: yardstrong@163.com
password: ****************
### 配置文件存放路径,可以按照服务来划分目录
search-paths:
- citizens-service
- goods-service
label: master
###-----------------------------------------------zuul
zuul:
### 解决重定向问题
add-host-header: true
routes:
api-citizens:
path: /api-citizens/**
service-id: citizens-service
api-goods:
path: /api-goods/**
service-id: goods-service
### 避免敏感请求头被过滤 - 方法1
# sensitive-headers:
### 避免敏感请求头被过滤 - 方法2
# custom-sensitive-headers: false
### url 模式
# api-test:
# path: /api-test/**
# url: http://localhost:999/
### 另一种方式 <service-id>: <path>
# citizens-service: /api-citizens/**
# goods-service: /api-goods/**
### 不适用eureka:
#ribbon:
# eureka:
# enabled: false
#api-citizens:
# ribbon:
# listOfServers:
# - http://192.168.1.101:8010/
# - http://192.168.1.102:8010/
其中Eureka-Server服务使用了base-auth认证
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
super.configure(http);
}
}