最近在学习微服务架构过程中,项目启动成功,但在浏览器访问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,最后访问成功啦。


花花呀
375 声望23 粉丝

学无止境 做有灵魂的程序员