You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Admin UI不可见(返回404)问题求助

解决Spring Boot Admin Server 1.5.6 UI 404问题

我之前也碰到过这个版本的类似坑,给你梳理几个核心排查方向和解决方案:

1. 确认依赖配置是否完整

1.5.x版本的Spring Boot Admin(SBA)不会自动包含UI模块,必须单独引入对应的UI starter,这是最容易踩的坑。检查你的构建文件:

Maven示例(pom.xml):

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server</artifactId>
    <version>1.5.6</version>
</dependency>
<!-- 必须单独加这个UI依赖 -->
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-server-ui</artifactId>
    <version>1.5.6</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Gradle示例(build.gradle):

compile('de.codecentric:spring-boot-admin-server:1.5.6')
compile('de.codecentric:spring-boot-admin-server-ui:1.5.6')
compile('org.springframework.boot:spring-boot-starter-web')

2. 检查启动类注解

启动类上必须标注@EnableAdminServer,这个注解负责注册UI的路由映射,少了它UI肯定无法访问:

import de.codecentric.boot.admin.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer // 关键注解,不能漏
public class AdminServerApp {
    public static void main(String[] args) {
        SpringApplication.run(AdminServerApp.class, args);
    }
}

3. 排查静态资源是否被拦截

如果项目里自定义了WebMvc配置或Spring Security,很可能不小心拦截了UI的静态资源:

自定义WebMvcConfigurer的情况

如果重写了addResourceHandlers,要确保放行SBA UI的资源路径:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    // 放行UI的HTML和静态资源
    registry.addResourceHandler("/*.html")
            .addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/css/**", "/js/**", "/img/**", "/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/css/",
                                 "classpath:/META-INF/resources/js/",
                                 "classpath:/META-INF/resources/img/",
                                 "classpath:/META-INF/resources/webjars/");
}

Spring Security配置的情况

如果启用了安全验证,需要允许UI相关资源的匿名访问:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                // 放行UI所有入口和静态资源
                .antMatchers("/", "/login", "/css/**", "/js/**", "/img/**", "/webjars/**").permitAll()
                // 其他端点按需配置权限
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").permitAll();
    }
}

4. 检查上下文路径配置

如果你的application.properties/application.yml设置了server.context-path,比如:

server.context-path=/admin-server

访问UI时必须带上这个路径,比如http://localhost:8080/admin-server,而不是直接访问根路径。如果不确定,可以先临时注释掉上下文路径测试。

5. 清理缓存重启

最后试试清理构建缓存,执行mvn clean install(Maven)或gradle clean build(Gradle),然后重启应用,同时清空浏览器缓存再访问。


内容的提问来源于stack exchange,提问作者Dan Erez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:12:40