spring cloud 访问controller报(type=Not Found, status=404)错误

最近在学习微服务架构过程中,项目启动成功,但在浏览器访问controller对应的requestMapping的时候一直报There was an unexpected error (type=Not Found, status=404).错误。解决过程如下:
1. 检查了访问地址路径“`http://localhost:8089/client1/hello?name=w“`,对应的application.yml里面配置的端口号和上下文路径没有问题。
controller里面的mapping也没有问题。
2. 百度一下,网上说springboot+thymeleaf的项目需要添加thymeleaf依赖,而此项目只是
springboot。

3. 检查包路径。springboot扫描文件“`@ComponentScan(basePackages = {“com.spring.*”})“`,
由此springboot启动类的包必须是项目下的父路径,其他类的包路径必须是其子路径。

这里ApplicationClient.java是项目启动类,路径正确,而controller的路径不在ApplicationClient.java
的包路径下,扫描不到。问题就在这里啦,修改controller的路径为
com.xxx.helloworld.eureka.client.controllers,最后访问成功啦。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理