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

Spring Get请求无响应、注解无灰色Globe图标问题求助

Spring请求无响应及注解无Globe图标问题

问题描述

  • 跟随Spring教程操作,代码与讲师完全一致,但发送Get请求后无任何响应
  • @RequestMapping和@GetMapping注解旁未显示灰色Globe端点图标
  • 调用控制器端点时出现错误页面

代码片段

控制器代码

package Controller;

import model.Il;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/iller")
public class ILController {

    @GetMapping
    public ResponseEntity<List<Il>> getIller(){

        Il il1 = new Il("34", "Istanbul");
        Il il2 = new Il("06", "Ankara");
        List<Il> iller = Arrays.asList(il1, il2);

        return new ResponseEntity<>(iller, HttpStatus.OK);
    }
}

Il类代码

package model;

import lombok.Data;

@Data
public class Il {
    private String id;
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Il(){
        this.id = "defaultId";
        this.name = "defaultName";
    }

    public Il(String id, String name){
        this.id = id;
        this.name = name;
    }
}

排查解决方案

  • 检查启动类包路径:Spring Boot启动类必须位于Controller包的上级或同级目录。Spring默认仅扫描启动类所在包及其子包,若启动类包层级与控制器包不匹配,控制器无法被Spring识别。
  • 验证控制器加载状态:启动项目后查看控制台日志,若未出现类似Mapped "{[/iller],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<model.Il>> Controller.ILController.getIller()的日志,说明控制器未被加载,需调整包结构。
  • 确认请求地址正确性:正确请求地址应为http://localhost:8080/iller(默认端口8080),检查是否输错路径或端口。
  • 修复IDEA插件异常:重启IDEA或执行File -> Reload All Projects,确保Spring相关插件正常生效,解决Globe图标不显示问题。
  • Lombok依赖检查:虽然Il类手动实现了getter/setter,但需确认项目依赖中已引入Lombok,且IDEA安装了Lombok插件,避免序列化异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 10:15:33