1.Error starting ApplicationContext.
To display the auto-configuration report re-run your application with 'debug' enabled.
解决方法:
在yml配置文件中加入debug: true,因为默认的话是false
2.在集成mybatis时mapper包中的类没被扫描
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'com.app.mapper.UserMapper' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
"\r\n### Error updating database. Cause:
com.mysql.jdbc.MysqlDataTruncation:
Data truncation: Data too long for column 'password' at row 1\r\n###
数据库表password这个字段太短了,应该设长点
java.lang.ClassCastException:
com.app.entity.User cannot be cast to java.lang.Integer
4.用mybatis查询时报错
org.mybatis.spring.MyBatisSystemException:
nested exception is org.apache.ibatis.binding.BindingException:
Parameter 'user_type' not found. Available parameters are [2, 1, 0, param1, param2, param3]
原因:@Param注解缺失,当只有一个参数时,Mapper接口中可以不使用
public User getUser(String name);
有多个参数时就必须使用
public User getUser(@Param("name") String name,@Param("password") String password);
org.apache.ibatis.binding.BindingException:
Mapper method 'com.hoomsun.mybatis.dao.CostMapperDao.dongtaislq'
has an unsupported return type: class java.lang.String
dao接口类中对应的方法去掉返回值,用void,例如:
public void dongtaislq(Map map);
7.mybatis中集合与Stirng类型的比较
报错信息
invalid comparison: java.util.ArrayList and java.lang.String
原因:无法比较这两种类型
AND category_id IN
#{categoryIds}
在接收list的时候加了判断 list !=' ',引起了集合与Stirng类型的比较,所以报错,将判断条件改为 : list.size >0就可以了
AND category_id IN
#{categoryIds}
8.保存对象数据进数据库后根据ID查询并返回该对象时为null
insert into user(username,password,nickname) values (#{username},#{password},#{nickname})
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2a5ca7d7] was not
registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@9a51d74] will not be managed by Spring
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2a5ca7d7]
解决方法:
确保有可用的连接池被使用,引入第三方连接池要做好配置
15.SpringBoot项目中service层互相引用
Description:
The dependencies of some of the beans in the application context form a cycle:
xxxController (field private aaaService xxxController.aaaService)
┌─────┐
| aaaImpl defined in file [aaaImpl.class]
↑ ↓
| bbbImpl (field private aaaService bbbImpl.orderService)
└─────┘
Caused by: org.springframework.boot.context.properties.bind.UnboundConfigurationPropertiesException:
The elements [spring.resources.chain.gzipped] were left unbound.