java - 导航器无法访问 RequestMapping

标签 java spring spring-boot

我正在使用 Spring Boot,并尝试显示 get 请求。我正在使用 2 个类:Greeting.javaGreetingController:

    package greeting;

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;
    }
}

我的 Controller 是 GreetingController.java :

public class GreetingController {

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

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

当我插入此网址(http://localhost:8080/greeting?name=gabriel)时,我在导航器上收到此错误:

  Whitelabel Error Page

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

Thu Mar 10 19:35:17 CET 2016
There was an unexpected error (type=Not Found, status=404).
No message available

我不明白为什么他找不到该页面。 如果有人可以帮助我:)

谢谢

最佳答案

映射 /greeting 存在,但发生错误,导致重定向到尚未配置的位置 /error

关于java - 导航器无法访问 RequestMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35924636/

相关文章:

java - Android NameValuePair 发送值

java - java反射newinstance构造函数参数数量错误

java - Spring 表单中可变数量的字段

spring-boot - 如何使用 CassandraAutoConfiguration 在 spring boot 应用程序和 cassandra 之间配置 ssl?

spring-boot - 根据异常类型调用ContainerStoppingErrorHandler

java - 由 : com. mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException 引起

java - 警告 : No file found for:/sign

java - 将类型化依赖项的集合转换为树

java - 限制 Flex/BlazeRS 和 Tomcat 之间的 HTTP 请求参数大小?

java - Spring RESTful Web 服务和 bean "request"和 "session"范围