【问题标题】:Rest template application fails休息模板应用程序失败
【发布时间】:2019-08-19 08:06:46
【问题描述】:

我已经为带有 rest 控制器的 springboot 编写了一个简单的代码。它运行良好,但没有到达终点。

我的应用程序类:

@SpringBootApplication
public class SpringbootRestTemplateDemo {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootRestTemplateDemo.class, args);
        System.out.println("Springboot Rest template demo");
    }

}

我的控制器类:

@RestController
public class ProductController {

    @RequestMapping(value="/product/details", method=RequestMethod.GET)
    public String getProduct() {
        return "Product details";

    }
}

我希望使用 get 请求得到一个简单的消息,但它没有到达端点。 输入: http://localhost:8080/product/details

输出:

Whitelabel 错误页面 此应用程序没有明确的映射 /error,因此您将其视为后备。

2019 年 3 月 28 日星期四 19:34:44 IST 出现意外错误(type=Not 找到,状态=404)。没有可用的消息

【问题讨论】:

    标签: spring-boot resttemplate


    【解决方案1】:

    我们可能需要查看文件夹结构才能完全理解。我目前的猜测是您的主类可能不在其他类之上的根包中。

    当您运行 Spring Boot 应用程序时(即使用 @SpringBootApplication 注解的类),Spring 将仅扫描您的主类包下的类。

    查看上一个答案:This application has no explicit mapping for /error

    【讨论】:

    • 谢谢Shane,确实是您上面提到的文件夹结构问题。我改变了它,现在可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    相关资源
    最近更新 更多