eureka 加入密码认证 springboot-admin 加入密码认证

eureka 加入密码认证 springboot-admin 加入密码认证

  1. pom.xml 加入依赖

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
  2. application.properties 配置如下 用户名和密码

    #开启安全认证 用户名和密码
    spring.security.basic.enabled=true
    spring.security.user.name=admin
    spring.security.user.password=root

    eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@localhost:${server.port}/eureka/

  3. 加入配置类 WebSecurityConfig.java.

    package org.fh.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;
    import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    复制代码
     @Override
     protected void configure(HttpSecurity http) throws Exception {
     	
     	SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
     	successHandler.setTargetUrlParameter("redirectTo");
    
     	http.headers().frameOptions().disable();
     	
     	http.csrf().disable().authorizeRequests().antMatchers("/actuator/**").permitAll().anyRequest().authenticated().and().httpBasic();
     }

    }

注意:Eureka启动,报Failed at: ${replica.key} [in template "eureka/navbar.ftl 解决方案:设置的密码中可能有@符号"

相关推荐
苦瓜小生2 分钟前
【黑马点评学习笔记 | 实战篇 】| 7-达人探店
redis·笔记·后端·学习
jgyzl7 分钟前
2026.3.20 用EasyExcel实现excel报表的导入与导出
java·python·excel
Javatutouhouduan9 分钟前
SpringBoot如何快速精通?
java·spring boot·mybatis·java面试·后端开发·java编程·java程序员
iPadiPhone12 分钟前
破茧成蝶:从底层内核到 Java NIO/AIO 异步架构全解析
java·架构·nio
菜鸟小九17 分钟前
hot100(81-90)
java·数据结构·算法
皙然17 分钟前
线上问题定位与排查实战:从日志到优化的完整思路
java·jvm
无巧不成书021822 分钟前
Java核心技术全景解析:从白皮书到实战踩坑
java·开发语言
Roy_Sashulin24 分钟前
基于AI的Java编程平台
java·开发语言·人工智能·sashulin·deepseek
常利兵31 分钟前
Spring Boot缓存新玩法:一键切换,租户无忧
spring boot·后端·缓存
想你的液宝31 分钟前
Spring Boot @RestControllerAdvice:统一异常处理的利器
后端