小鬼妹妹编程史 2021-12-23 15:22 采纳率: 0%
浏览 13
已结题

eureka 注册中心 添加安全认证security 过滤csrf后 服务还是起不起来

问题遇到的现象和发生背景

项目注册中心有2个服务 没添加安全认证之前 eureka服务可以启动起来 添加安全认证后起不起来

操作环境、软件版本等信息

各依赖如下图:

img


server01 pom.xml


<!--    项目依赖  -->
    <dependencies>
<!--        netflix eureka server 依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
<!--        spring-boot-web 依赖  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--        spring-boot-security 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>
    </dependencies>
-----------------------------------------------------------------


-----------------------------------------------------------------
application.yml

server:
  port: 8761

spring:
  application:
    name: eureka-server  #应用名称
  #安全认证
  security:
    user:
      name: root
      password: 123

# 配置eureka  server注册中心
eureka:
  server:
    eviction-interval-timer-in-ms: 60000  #清理间隔(单位:毫秒 ,默认是 60*1000)
    enable-self-preservation: true  #true  :开启自我保护模式  ,false:关闭自我保护模式
  instance:
    hostname: localhost
    prefer-ip-address: true #是否使用ip地址注册
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
  client:
#    register-with-eureka: false  #是否将自己注册到注册中心  默认时true
#    fetch-registry: false        #是否从注册中心获取服务注册信息,默认是true
    service-url:
      defaultZoo: http://root:123@${eureka.instance.hostname}:8762/eureka/
-----------------------------------------------------------------
启动类:
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
    public static void main(String[] args) {

        SpringApplication.run(EurekaServerApplication.class);
    }
}
-----------------------------------------------------------------

配置csrf过滤

package com.wlm.config;

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;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    protected void configure(HttpSecurity http) throws Exception {
//        super.configure(http);
//        http.csrf().ignoringAntMatchers("/eureka/**");     两种都不能启动服务
        http.csrf().disable().authorizeRequests()
                .anyRequest().authenticated().and().httpBasic();
    }
}


以上是全部代码:服务1和服务2代码一样。服务就是启不起来 ,求指点迷津,哪里错了

img

  • 写回答

1条回答 默认 最新

  • 有问必答小助手 2021-12-25 11:48
    关注

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


    本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


    因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。

    评论

报告相同问题?

问题事件

  • 系统已结题 12月31日
  • 修改了问题 12月23日
  • 创建了问题 12月23日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器