Spring boot mybatis : Error creating bean with name 'com.github.pagehelper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed;

报错截图:

Spring boot mybatis  : Error creating bean with name 'com.github.pagehelper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed;

解决方法:

  只能扫描到自定义的mapper,不能扫描到其他文件。

  @MapperScan("com.streamax.s17.tms.dao.pper.repository")

1. 继承通用Mapper

  此接口不能同其他Mapper一起,该类不能被当做普通Mapper一样被扫描,否则会出错。

package com.streamax.s17.tms.dao.mapper.core;

import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.MySqlMapper; /**
* @author cf
* @date 2018/11/21
*/
public interface CoreMapper<T> extends BaseMapper<T>, MySqlMapper<T> {
}

2. 自定义Mapper继承CoreMapper

  自定义的 Mapper 通过对应有xml的映射文件

  自定义Mapper.java要特别注意,不能同上面的Mapper定义在同一个包下

package com.streamax.s17.tms.dao.mapper.repository;

import com.streamax.s17.tms.dao.entity.TokenEntity;
import com.streamax.s17.tms.dao.mapper.core.CoreMapper; /**
* @author cf
* @date 2018/11/21
*/
public interface TokenMapper extends CoreMapper<TokenEntity> { /**
* 根据 entityId 查询token
*
* @param entityId
*/
TokenEntity selectByEntityId(String entityId); }

3. MapperScan

package com.streamax.s17.tms;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
// 只扫描自定义mapper所在包,不能扫描到继承通用mapper所在包
@MapperScan("com.streamax.s17.tms.dao.mapper.repository")
public class TmsApplication {
public static void main(String[] args) {
SpringApplication.run(TmsApplication.class, args);
}
}

 

 

上一篇:2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)


下一篇:CentOS6.5下安装apache2.2和PHP 5.5.28