gpt4 book ai didi

java - 使用Springboot部署REST服务: whitelabel error

转载 作者:行者123 更新时间:2023-12-01 08:52:52 26 4
gpt4 key购买 nike

我正在尝试学习使用 SpringBoot 部署简单的 REST 服务。以下是我正在使用的类文件。

@SpringBootApplication
public class App {

public static void main(String[] args) {

SpringApplication.run(App.class, args);
int a= 5;
int b=10;
Addition.addR(a, b);
}
}

@RestController
@RequestMapping(value="/spring/examples")
public class Addition {

@RequestMapping(value="/", method= RequestMethod.GET)
public static String addR(int a, int b){
String c ;
c= a + b + " = Addition of two Numbers";
return c;
}
}

当我运行主类时,出现错误:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

有什么线索可以说明是什么原因造成的吗?

最佳答案

我认为仅仅启动主类就不会出现错误页面。因为这个 Whitelabel Error Page 是 spring 错误页面的默认响应。所以你在发出请求后就会得到这个页面。

像这样更改您的 addR 代码:

 @RequestMapping(method = RequestMethod.GET)
public static String addR(int a, int b) {
String c = a + b + " = Addition of two Numbers";
return c;
}

并发送如下请求:http://localhost:8080/spring/examples?a=1&b=2。预期的响应应如下所示:3 = 两个数字相加

如果你想检查你的主类是否也可以工作,只需在控制台上打印它 System.out.println(Addition.addR(1, 3));

关于java - 使用Springboot部署REST服务: whitelabel error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42274529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com