mybatis mapper文件找不到_springboot集成mybatis时,配置mapper路径

原文链接:

springboot集成mybatis时,配置mapper路径_qq_16248977的博客-CSDN博客​blog.csdn.net
v2-2a5027b5bff83f50a189c6146b4f7548_ipico.jpg

一、使用默认的配置文件名

使用默认的配置文件application.yml时,mapper文件放在resource下,指定classpath路径配置(yml格式)

mybatis

报错: 找不到指定的mapper文件

Caused by: java.io.FileNotFoundException: class path resource [mapper/*Mapper.xml] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
	at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:406)
	at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:380)
	at org.mybatis.spring.SqlSessionFactoryBean.getObject(SqlSessionFactoryBean.java:547)
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration.sqlSessionFactory(MybatisAutoConfiguration.java:153)
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$f59d01c7.CGLIB$sqlSessionFactory$1(<generated>)
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$f59d01c7$$FastClassBySpringCGLIB$$8d295b3d.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
	at org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$f59d01c7.sqlSessionFactory(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 66 more

解决:

mybatis-plus:
  config-location: classpath:mapper/*Mapper.xml

原因:

注意自己使用的时mybatis还是mybatis-plus来修改配置文件.

二、自定义的配置文件

使用默认的配置文件

SpringBootApplication

配置mapper路径时,路径代表的是与配置文件的相对路径

mybatis.config-location: mapper/*Mapper.xml

目录结构

customize.properties
  logback.xml
- mapper
	DemoMapper.xml

————————————————

版权声明:本文为CSDN博主「Tony丶Hsu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

er路径_qq_16248977的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值