无法访问Eureka Server仪表盘,出现404 Not Found错误求助
确认启动类核心注解
启动类必须添加@EnableEurekaServer注解,这是激活Eureka Server功能的必要条件,缺少该注解时,应用仅作为普通Spring Boot项目运行,不会加载仪表盘的访问映射。核对依赖配置正确性
pom.xml中必须引入Eureka Server的starter依赖,示例配置如下(需匹配Spring Boot与Spring Cloud的兼容版本):<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>版本兼容参考:Spring Boot 2.7.x对应Spring Cloud 2021.0.x(Jubilee),Spring Boot 3.x对应Spring Cloud 2022.0.x(Kilburn),版本不匹配会导致静态资源加载失败。
检查配置文件关键项
在application.yml/application.properties中,确保Eureka Server的基础配置正确,至少包含:server: port: 8761 eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/其中
register-with-eureka和fetch-registry设为false,避免自身作为客户端注册,同时保证service-url地址正确,这会直接影响仪表盘页面的加载路径。放行Eureka相关资源(如有Spring Security)
若项目集成了Spring Security,需放行Eureka的端点和静态资源,否则会被拦截导致404。Spring Boot 2.7+版本可添加如下配置类:import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.SecurityFilterChain; public class WebSecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf.ignoringAntMatchers("/eureka/**")); return http.build(); } }清理缓存后重新构建启动
编译缓存可能导致资源加载异常,执行mvn clean install(Maven项目)或./gradlew clean build(Gradle项目)清理缓存并重新构建,之后重启应用,访问http://localhost:8761验证。
内容的提问来源于stack exchange,提问作者s4n17a

