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 解决方案:设置的密码中可能有@符号"

相关推荐
每天进步一点_JL4 分钟前
JVM 内存模型与 OOM 排查:从入门到实战
后端
TE-茶叶蛋4 分钟前
深入研究 yudao-framework 模块:Java 编程能力提升指南
java·开发语言
逻辑驱动的ken12 分钟前
Java高频考点场景题24
java·开发语言·面试·职场和发展·求职招聘
gwjcloud18 分钟前
Kubernetes从入门到精通(高级篇)04
云原生·容器·kubernetes
兔小盈22 分钟前
多线程-(五)线程安全之内存可见性
java·开发语言·多线程
REDcker26 分钟前
个人博客网站建设指南 Markdown资产化与静态站选型部署
前端·后端·博客·markdown·网站·资产·建站
阿里云云原生35 分钟前
阿里云微服务引擎 MSE 及 API 网关 2026 年 4 月产品动态
微服务·云原生
Supersist44 分钟前
【设计模式03】使用模版模式+责任链模式优化实战
后端·设计模式·代码规范
彩旗飘飘44 分钟前
手把手教你用 Spring Cloud Alibaba 搭建毕设级微服务架构:从单体到分布式的完整演进实录
spring cloud·微服务
CeshirenTester1 小时前
LangChain的工具调用 vs 原生Skill API:性能差在哪儿?
java·人工智能·langchain