A component required a bean of type ‘com.*.*.Mapper‘ that could not be found.


A component required a bean of type ‘com...Mapper’ that could not be found.


方法一
启动项目显示找不到Mapper文件,之后根据查到的信息在启动类添加了@MappertScan(basePackages = {"com.xxx.xxx.mapper"})
的注解,引入了MappertScan对应的class,还是提示之前的错误,错误如下等等,省略了一些。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-04-16 16:59:42.358 ERROR 19972 --- [           main] o.s.boot.SpringApplication               : Application run failed

Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
	at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.26.jar:5.3.26]
	at org.mybatis.spring.support.SqlSessionDaoSupport.checkDaoConfig(SqlSessionDaoSupport.java:125) ~[mybatis-spring-2.1.0.jar:2.1.0]
	at org.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:73) ~[mybatis-spring-2.1.0.jar:2.1.0]
	at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44) ~[spring-tx-5.3.26.jar:5.3.26]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.26.jar:5.3.26]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.26.jar:5.3.26]
	... 30 common frames omitted

方法二
是修改pox.xml里的依赖,亲测对我的没用,依旧一堆报错。修改的内容如下:
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis-spring-boot-starter.version}</version> </dependency>
最主要的一点是,我是直接在idea创建项目并安装了mabatis等等模块啥的,按理来说不会出现版本对应出错的问题。
方法三
刷新maven依赖,但是没有解决我的问题。
方法五
启动类添加如下注解:

@ComponentScan(basePackages = {"com.*.*.mapper"})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

接口类添加:

@Mapper

在查找的时候,还看见一个问题,关于扫描不到mapper文件,有两块地方的一些引用不可以同时写上,等我找到我再进行二编吧。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值