问题:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'top.kittygirl.xdtoutiao.InitDatabaseTests': Unsatisfied dependency expressed through field 'userDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'top.kittygirl.xdtoutiao.dao.UserDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
解决:
测试类的前面加上
@RunWith(SpringRunner.class) @SpringBootTest
参考资料:
https://zhidao.baidu.com/question/1992834174150299427.html
https://zhuanlan.zhihu.com/p/26794187
问题:
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
解决:
数据库没有打开
问题:
org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of class path resource [init-schema.sql]: CREATE TABLE `user` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(64) NOT NULL DEFAULT '', `password` VARCHAR(128) NOT NULL DEFAULT '', `salt` VARCHAR(32) NOT NULL DEFAULT '', `head_url` VARCHAR(256) NOT NULL DEFAULT '', PRIMARY KEY ('id'), UNIQUE KEY `name` (`name`) )ENGINE = InnoDB DEFAULT CHARSET = utf8; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''id'), UNIQUE KEY `name` (`name`) )ENGINE = InnoDB DEFAULT CHARSET = utf8' at line 1
解决:
单引号''与 反单引号``用错
在MySQL中``是为了区分MYSQL的保留字与普通字符而引入的符号,如果表名、字段名中没有保留关键字,则可以省略,因此尽量不要使用反单引号
参考资料:
问题:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'like_count' in 'class top.kittygirl.xdtoutiao.model.News'
解决:
在DAO中的sql语句中传入的参数#{}不是数据库表中定义的量like_count,而是model中定义的变量名likeCount,MyBatis会将model中定义的变量和sql中的参数联系起来
参考资料:
问题:
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tiket' in 'field list'
### The error may involve top.kittygirl.xdtoutiao.dao.LoginTicketDAO.addTicket-Inline
### The error occurred while setting parameters
### SQL: insert into login_ticket ( user_id, expired, status, tiket ) values (?,?,?,?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tiket' in 'field list'
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tiket' in 'field list'
解决:
拼写错误