mybatis的mapper找不到

Description:
Field departmentMapper in .service.DepartmentService required a bean of type ‘.service.DepartmentMapper’ that could not be found.
Action:
Consider defining a bean of type ‘*.service.DepartmentMapper’ in your configuration.

在确定各种配置没有问题的情况下,考虑在mapper上增加@Mapper注解,或者在入口类上增加@MapperScan(mapper的位置),即可解决该问题。
此时,注入该mapper的Service类,在IDE中还是提示“cannot autowire no bean of ‘departmentMapper’ type found”,但是不影响使用。

@Service
public class DepartmentService {
    @Autowired
    DepartmentMapper departmentMapper;

    public Department getDepartment(){
        Department d = departmentMapper.selectByPrimaryKey(new Integer(1));
        return d;
    }
}

你可能感兴趣的:(springboot)