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

相关推荐
盐水冰4 分钟前
【烘焙坊项目】补充完善(1)- SpringAI大模型接入
java·后端·大模型
cch891810 分钟前
C++与PHP:7大核心差异全解析
java·开发语言
softshow102610 分钟前
SpringCloud Redis与分布式
redis·分布式·spring cloud
-南帝-16 分钟前
RocketMQ2.3.5+SpringBoot 3.2.11+ java17安装-集成-测试案例
java·spring boot·rocketmq
yuanlaile19 分钟前
Go语言(Golang)2026年3月整理经典面试常见问题面试题汇总,建议收藏
后端·golang·go语言面试题·golang后端开发·2026golang面试
蜜獾云31 分钟前
Spring Cloud微服务如何设计异常处理机制
spring·spring cloud·微服务
斌糖雪梨36 分钟前
spring registerBeanPostProcessors(beanFactory) 源码详解
java·后端·spring
Nontee39 分钟前
面试准备(Reids存粹问题版)
java·面试
2601_9498179243 分钟前
spring-ai 下载不了依赖spring-ai-openai-spring-boot-starter
java·人工智能·spring
九皇叔叔43 分钟前
006-SpringSecurity-Demo 跨域(CORS)配置
java·springboot3·springsecurity·跨域·cors