【问题标题】:How to fix error "Whitelabel Error Page" in Spring-boot如何在 Spring-boot 中修复错误“Whitelabel Error Page”
【发布时间】:2019-09-10 19:59:04
【问题描述】:

我尝试通过 Spring-boot 做 API webservice 但我得到一个错误 “白标错误页面 此应用程序没有 /error 的显式映射,因此您将其视为后备。

2019 年 4 月 21 日星期日 13:42:49 ICT 出现意外错误(类型=未找到,状态=404)。 没有可用的消息”

ArrestGetByConApplication.java : 

package com.arrestbycon.arrestGetByCon;
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan
public class ArrestGetByConApplication {

public static void main(String[] args) {
    SpringApplication.run(ArrestGetByConApplication.class, args);
}

}

and some of my controller :

package com.arrestbycont.arrestGetByCon;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.sql.*;
import java.util.ArrayList;
import com.arrestbycon.arrestGetByCon.Result;

@RestController
public class GetByCon {

    @RequestMapping(value = "/test", method = RequestMethod.GET)   
    public ArrayList<Result> getResult() {
      Integer arr_id;
      Integer off_id;
      String arr_code;
      String off_code;
      String off_name;

      ArrayList<Object> myArrlist = new ArrayList<Object>();

【问题讨论】:

  • 你能更精确一点吗?您想自定义错误页面吗?或者你不明白为什么你有这个答案?

标签: api spring-boot


【解决方案1】:

“白标页面”本身不是错误,而是 Spring 返回的模板,以防出现没有其他自定义处理的错误。

在提到的这种特定情况下,错误显然是您尝试访问的控制器端点不存在(因此是 404 代码)。只需确保您使用正确的 HTTP 方法对正确的端点进行 API 调用即可。

【讨论】:

    猜你喜欢
    • 2020-01-26
    • 2020-07-30
    • 2019-05-03
    • 2023-02-22
    • 2018-07-22
    • 2019-04-04
    • 2020-04-15
    • 1970-01-01
    • 2021-11-12
    相关资源
    最近更新 更多