【问题标题】:Deploying REST services using Springboot: whitelabel error使用 Springboot 部署 REST 服务:whitelabel 错误
【发布时间】:2017-02-16 12:52:27
【问题描述】:

我正在尝试学习使用 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.

有什么原因导致的吗?

【问题讨论】:

    标签: java rest spring-boot


    【解决方案1】:

    我认为您不会仅通过启动主类来获得错误页面。因为这个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 = Addition of two Numbers

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

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2023-03-13
      • 2021-12-20
      • 2020-09-22
      • 1970-01-01
      • 2012-06-08
      • 2019-05-03
      • 2023-04-01
      • 2012-09-05
      相关资源
      最近更新 更多