A component required a bean of type ‘com.*.*.Mapper‘ that could not be found.
在查找的时候,还看见一个问题,关于扫描不到mapper文件,有两块地方的一些引用不可以同时写上,等我找到我再进行二编吧。最主要的一点是,我是直接在idea创建项目并安装了mabatis等等模块啥的,按理来说不会出现版本对应出错的问题。的注解,引入了MappertScan对应的class,还是提示之前的错误,错误如下等等,省略了一些。是修改pox.xml里的依赖,亲测对我的没用,依旧一堆报错。启动项
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文件,有两块地方的一些引用不可以同时写上,等我找到我再进行二编吧。
更多推荐
所有评论(0)