spring boot 返回json There was an unexpected error (type=Not Found, status=404).

在做一个spring boot的小demo的时候,完全是按照其他人的例子来做的,但是运行以后返回界面始终是404:

Whitelabel Error Page
 
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 17 13:12:15 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available
页面上也不明说错了什么,查了很多地方都说是Application类的位置应该放在最外面的包中,一小部分提示缺少依赖,但都没有解决这个问题。

最好发现是controller类的的一个注解写错了。

原来:

@Controller
@RequestMapping("/user")
public class LoginController {
    
    @Autowired
    UserService userService;
现在:

@RestController
@RequestMapping("/user")
public class LoginController {
    
    @Autowired
    UserService userService;
就是把@Controller改为@RestController就可以了
--------------------- 
作者:EchoDSun 
来源:CSDN 
原文:https://blog.csdn.net/weixin_39513118/article/details/79973366 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/haiyang4988/article/details/84819442