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

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

  1. pom.xml 加入依赖

    org.springframework.boot spring-boot-starter-security
  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 解决方案:设置的密码中可能有@符号"

相关推荐
程序员晓琪3 分钟前
约定大于配置:基于 Java 包名自动生成 API 版本路由的最佳实践
java·spring boot·后端
Flittly8 分钟前
【AgentScope Java新手村系列】(11)中断与恢复
java·spring boot·spring
银卡12 分钟前
RAG Embedding 模型选型
后端
用户5598224812213 分钟前
Claude Code + DeepSeek V4 Pro 说"不行"时,别信
后端
众少成多积小致巨34 分钟前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
leeyi40 分钟前
Manus Agent:一个全能 AI,和一支研究团队
后端·aigc·agent
东坡白菜44 分钟前
破局全栈:前端开发的Java入门实战记录—JPA(2)
java·后端
代码丰1 小时前
RAG 系统如何实现全链路追踪:AOP 埋点与流式调用追踪实践
后端
小码编匠1 小时前
C# 工控上位机必备:数据转换工具类与十个核心模块
后端·c#·.net
神奇小汤圆2 小时前
一文读懂 OpenAI Codex 源码的原理、架构与未来
后端