问题遇到的现象和发生背景
项目注册中心有2个服务 没添加安全认证之前 eureka服务可以启动起来 添加安全认证后起不起来
操作环境、软件版本等信息
各依赖如下图:
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代码一样。服务就是启不起来 ,求指点迷津,哪里错了