Eureka Server 创建

1、Spring boot 版本

<version>2.2.5.RELEASE</version>

2、Eureka POM 依赖

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

3、Eureka 配置

# 设置服务端口
server.port=7777
# 设置服务地址
server.address=192.168.3.71
#是否将自己注册到eureka-server中,默认的为true
eureka.client.registerwitheureka=false
#是否从eureka-server中获取服务注册信息,默认为true
eureka.client.fetchregistry=false
#关闭自我保护
eureka.server.enable-self-preservation=false
#启用主动失效,并且每次主动失效检测间隔为5s
eureka.server.eviction-interval-timer-in-ms=5000

4、开启基于http basic的安全认证
4.1、POM依赖

      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.2.5.RELEASE</version>
      </dependency>

4.2、配置

# 开启基于http basic的安全认证
spring.security.basic.enabled=true
# 设置安全认证用户名
spring.security.user.name=admin
# 设置安全认证密码
spring.security.user.password=********

4.3、说明
新版的security默认启用了csrf检验,需在eureka服务端配置security的csrf检验为false,示例如下:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@Configuration
@EnableWebSecurity
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        super.configure(http);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

金色稻子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值