java注解自动加载接口,spring boot 自动生成的mapper 接口文件无法注入,已经添加@MapperScan 注解...

本文介绍了一个SpringBoot项目中整合MyBatis时遇到的问题,主要问题是Service层的CategoryMapper未能正确注入CategoryMapper Bean。文章探讨了可能的原因,并提出了相应的解决思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/p>

PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

connectionURL="${spring.datasource.url}"

userId="${spring.datasource.username}"

password="${spring.datasource.password}">

spring boot 入口文件:

package com.mall.demo;

import org.mybatis.spring.annotation.MapperScan;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

@MapperScan(basePackages = "com.mall.demo.mapper")

public class MallProjectApplication {

public static void main(String[] args) {

SpringApplication.run(MallProjectApplication.class, args);

}

}

使用的编辑器是IDEA ,service实现类中使用Autowired注入,但运行 依然提示没有注入成功。

错误信息如下:

Description:

Field categoryMapper in com.mall.demo.service.impl.CategoryServiceImpl required a bean of type 'com.mall.demo.mapper.CategoryMapper' that could not be found.

Action:

Consider defining a bean of type 'com.mall.demo.mapper.CategoryMapper' in your configuration.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值