创作不易,多多点赞,感谢大家的关注,不定期的根据实战经验踩坑与大家分享
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.7.17</version>
</dependency>
增加配置
@EnableWebSecurity
public class EurakeConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
// 开启认证
httpSecurity.authorizeRequests()
//.mvcMatchers("/health").permitAll().anyRequest().authenticated()
.and()
.httpBasic()
.and()
.formLogin()
.disable()
////关闭csrf
.csrf()
.disable();
httpSecurity.authorizeRequests();
return httpSecurity.build();
}
}
设置登录密码
spring.security.user.password=password
spring.security.user.name=username
连接eureka配置
eureka.client.serviceUrl.defaultZone=http://username:password@127.0.0.1:8080/eureka