No MyBatis mapper was found in ‘[xx]‘ package. Please check your configuration.
今天本菜鳥搭建環境時,發現控制臺有個警告,由于強迫癥,決定干死它!警告信息如所示:
No MyBatis mapper was found in ‘[xx]’ package. Please check your configuration.
15:49:23.328 [main] DEBUG com.MainApplication - Running with Spring Boot v2.4.0, Spring v5.3.1 15:49:23.330 [main] INFO com.MainApplication - No active profile set, falling back to default profiles: default 15:49:25.811 [main] DEBUG tk.mybatis.spring.mapper.ClassPathMapperScanner - Identified candidate component class: file [D:\workspace\springboot_test\target\classes\com\example\dao\PersonMapper.class] 15:49:25.812 [main] DEBUG tk.mybatis.spring.mapper.ClassPathMapperScanner - Creating MapperFactoryBean with name 'personMapper' and 'com.example.dao.PersonMapper' mapperInterface 15:49:25.813 [main] DEBUG tk.mybatis.spring.mapper.ClassPathMapperScanner - Enabling autowire by type for MapperFactoryBean with name 'personMapper'. 15:49:26.133 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter. 15:49:27.261 [main] WARN org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[com]' package. Please check your configuration. 15:49:28.056 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http) 15:49:28.120 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"] 15:49:28.121 [main] INFO org.apache.catalina.core.StandardService - Starting service [Tomcat] 15:49:28.122 [main] INFO org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.39] 15:49:28.330 [main] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext 15:49:28.331 [main] INFO org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 4906 ms 15:49:29.871 [main] INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor' 15:49:30.311 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"] 15:49:30.362 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path '' 15:49:30.381 [main] INFO com.MainApplication - Started MainApplication in 7.873 seconds (JVM running for 19.261)結論
將tk.mybatis.spring.annotation.MapperScan 改為 org.mybatis.spring.annotation.MapperScan
package com;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Service; import tk.mybatis.spring.annotation.MapperScan;import javax.annotation.Resource;/*** 類描述* 主啟動類** @author * @version 1.0* @date 2020/12/11 10:51*/ @SpringBootApplication @ComponentScan(value = {"com.example.controller"}, useDefaultFilters = false, includeFilters = {@ComponentScan.Filter(value = {Autowired.class, Resource.class, Controller.class}) }) @ComponentScan(value = {"com.example.service"}, useDefaultFilters = false, includeFilters = {@ComponentScan.Filter(value = {Autowired.class, Resource.class, Service.class}) }) //@MapperScan(basePackages = {"com.example.dao"}, properties = { // "mappers=tk.mybatis.mapper.common.Mapper", // "notEmpty=false", // "identity=Mysql", // "ORDER=BRFORE" //}) @org.mybatis.spring.annotation.MapperScan(basePackages = {"com.example.dao"}) public class MainApplication {public static void main(String[] args) {SpringApplication.run(MainApplication.class, args);} } 16:13:41.250 [main] DEBUG com.MainApplication - Running with Spring Boot v2.4.0, Spring v5.3.1 16:13:41.252 [main] INFO com.MainApplication - No active profile set, falling back to default profiles: default 16:13:44.225 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter. 16:13:44.978 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http) 16:13:45.000 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8080"] 16:13:45.001 [main] INFO org.apache.catalina.core.StandardService - Starting service [Tomcat] 16:13:45.002 [main] INFO org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.39] 16:13:45.198 [main] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext 16:13:45.199 [main] INFO org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 3819 ms 16:13:46.164 [main] INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor' 16:13:47.148 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8080"] 16:13:47.199 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path '' 16:13:47.222 [main] INFO com.MainApplication - Started MainApplication in 6.899 seconds (JVM running for 19.042)原因
由于本人在項目中使用了tk.mybatis,
所以MapperScan使用了tk.mybatis.spring.annotation.MapperScan,
而警告是“org.mybatis.spring.mapper.ClassPathMapperScanner”,
將tk.mybatis.spring.annotation.MapperScan 改為 org.mybatis.spring.annotation.MapperScan后,
再次啟動服務,警告沒有了
總結
本人也查了不少帖子,注解方式和配置文件方式都試了,按照文檔也仔細檢查過自己的文件,都沒有問題,發現這個問題其實有些慚愧,沒注意細節。
當然,這個問題或許有其他原因,但是本菜鳥未遇到,不敢亂說,也不敢亂推薦文章,還請見諒。
疑問
將tk.mybatis.spring.annotation.MapperScan 改為 org.mybatis.spring.annotation.MapperScan,雖然警告沒了,也能正常使用,但是是否存在隱藏的問題?請大佬賜教,不勝感激!
總結
以上是生活随笔為你收集整理的No MyBatis mapper was found in ‘[xx]‘ package. Please check your configuration.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 硬件:选购CPU和显卡需了解的参数,TD
- 下一篇: 硬件:U盘无法识别的解决方案