Spring构建了一个RESTful Web服务教程,whitelabel错误页面

时间:2015-09-17 17:28:26

标签: java spring rest spring-tool-suite spring-rest

问题: 为什么我会收到whitelabel错误页面?

确切错误:

Whitelabel错误页面

此应用程序没有/ error的显式映射,因此您将此视为后备。

Thu Sep 17 12:11:02 CDT 2015
    There was an unexpected error (type=Not Found, status=404).
    No message available

背景 我正在关注spring.io入门指南,使用spring构建一个RESTful Web服务。

https://spring.io/guides/gs/rest-service/#scratch

我正在使用Spring工具套件,我按照教程进行了修改。

我的代码:

Greeting.java

package hello;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content){
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }
}

GreetingController.java

package hello;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
public class GreetingController {

    private final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();


    @RequestMapping("/greeter")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        return new Greeting( counter.incrementAndGet(), String.format(template, name));
    }

}

Application.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

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

}

0 个答案:

没有答案