Eureka Server 加上安全认证之后,服务无法注册

服务注册中心加了安全认证之后,然后我运行eureka client 。。。发现。。。。
这里写图片描述
报错了,注册不了。。。后来才发现,注册地址要改一下。。改成下面这样:

eureka:
  client:
    service-url:
      defaultZone: http://boy:coolBoy@192.168.1.15:8000/eureka/

在地址里加上用户名密码,然后运行还是报错,是因为新版本的security默认开启csrf了,关掉就好了,新建一个配置类,看下面:

package com.yezi.dreamspark.dreamsparkserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
   http.csrf().disable(); //关闭csrf
    http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); //开启认证
    }

}

然后运行,完美!!成功注册。
这里写图片描述

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值