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

Spring Boot开发中localhost页面加载异常及无法自定义问题求助

解决Spring Boot启动后出现陌生登录页的问题
  • 检查是否意外引入Spring Security依赖
    新手搭建Spring Boot项目时,很容易误选spring-boot-starter-security依赖。这个依赖会自动开启基础身份认证,默认生成登录页,不管你换哪个端口都会触发。

    • 打开pom.xml(Maven)或build.gradle(Gradle),如果找到spring-boot-starter-security相关依赖,直接删除,然后重启项目。
    • 如果你需要保留Security功能,就新建一个配置类放开访问权限:
      import org.springframework.context.annotation.Configuration;
      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;
      
      @Configuration
      @EnableWebSecurity
      public class SecurityConfig extends WebSecurityConfigurerAdapter {
          @Override
          protected void configure(HttpSecurity http) throws Exception {
              http.authorizeRequests()
                  .anyRequest().permitAll()
                  .and().csrf().disable();
          }
      }
      
  • 确认自定义页面的存放位置
    自定义首页要放在正确的目录下:

    • 静态HTML文件直接放到src/main/resources/static目录(比如index.html)
    • 用Thymeleaf等模板引擎的话,放到src/main/resources/templates目录
      确保文件名和路径正确,处理完Security配置后再访问端口就能看到自己的页面。
  • 强制刷新浏览器缓存
    有时候浏览器会缓存旧页面,按Ctrl+Shift+R强制刷新,或者用无痕模式打开页面测试,避免缓存干扰。

内容的提问来源于stack exchange,提问作者Nivetika Rajasekar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 02:50:26