springboot与mybatis整合各种报错

启动项目报错

错误1:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field faceCustomerMapper in com.example.demo.service.impl.FaceServiceImpl required a bean of type 'com.example.demo.mapper.FaceCustomerMapper' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.example.demo.mapper.FaceCustomerMapper' in your configuration.

报错大意找不到mapper文件

解决办法:在启动类里面加上MapperScan注解,括号里面的注解写自己的

@MapperScan("com.example.demo.mapper")

springboot与mybatis整合各种报错

 

同样的如果controller和service扫描不到的话也加@ComponentScan 这个注解就好了。

 

错误2:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.mapper.FaceCustomerMapper.selectByPrimaryKey 

原因1:xml中的namespace路径要写对

springboot与mybatis整合各种报错

原因2 application.yml 配置文件的mybatis配置要加,而且不能写错

springboot与mybatis整合各种报错

如果一开始相对路径不行的话,一定要用绝对路径试一下。

springboot与mybatis整合各种报错

注意一下 我 的XML文件是放在配置文件下面的

springboot与mybatis整合各种报错

 

错误3:启动都正常搞一个测试类测试发现还报错

java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';autoReconnectForPools=true&noAccessToProcedureBodies=true&useunicode=true&zeroDateTimeBehavior=convertToNull'.

这种就是数据库链接不对 修改一下就好了 用&拼接,去掉amp;