写了Controller类返回json数据文件时候报错
在这里插入图片描述

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

在这里插入图片描述

回到idear发现报错:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
The error may exist in edu/xalead/dao/ItemDao.java (best guess)
The error may involve edu.xalead.dao.ItemDao.selectAll
The error occurred while executing a query
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)] with root cause
java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)

猜测应该是数据库连接的问题,去application.yaml文件下查看数据库连接。

spring:
  application:
    name: item-service
  datasource:
    url: jdbc:mysql://localhost:3306/

路径不完整所以连接有问题

spring:
  application:
    name: item-service
  datasource:
    url: jdbc:mysql://localhost:3306/jdd

补全你的数据库路径,结果还是发现同样的错误!

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)] with root cause
java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)

再看一遍,原来是数据库的用户名和密码的错误!
这波啊,这波是一石二鸟…

datasource:
    url: jdbc:mysql://localhost:3306/jdd
    username: root
    password: 

把自己的数据库密码和用户名校正就好了!

最后在刷新一下网页,返回的数据与数据库中的数据匹配即成功。
在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐