spring之Web 应用程序启动警告 :No MyBatis mapper was found in . .. ,请检查您的配置

JustinYoung 阅读:11 2024-02-04 11:18:29 评论:0

我的配置是:

spring-4.2.3 
mybatis-3.3.0 
mybatis-spring-1.2.3 

映射器看起来像:
package com.vsi.idp.map.server.mapper; 
//imports... 
public interface SeniorMapper extends BaseMapper<Long, Senior> 
{ 
   @Results({...}) 
   @Select(...) 
   public List<Senior> query(...); 
} 

ServiceImpl 看起来像:
package com.vsi.idp.map.server; 
//imports... 
@Service("querySenior") 
public class SeniorQueryServiceImpl extends RemoteServiceServlet implements     SeniorQueryService 
{ 
    @Autowired 
    SeniorMapper mapper; 
 
    @Override 
    public List<Senior> query(Address address, String careType){...} 
} 

applicationContext.xml 看起来像:
<beans ... default-lazy-init="true"> 
   <!-- MyBatis Mapper Interfaces --> 
   <mybatis:scan base-package="com.vsi.idp.map.server.mapper" /> 
 
   //other configurations 
</beans> 

Spock 单元测试 如下所示, 按预期运行
@ContextConfiguration(locations = "file:war/WEB-INF/applicationContext.xml") 
public class SeniorQueryServiceImplTest extends Specification{ 
 
  @Autowired 
  SeniorQueryServiceImpl service 
 
  def "query by full address"(){ 
     //blabla 
  } 
} 

但是当启动 web 应用程序时,我收到了这个警告:
WARNING: No MyBatis mapper was found in '[com.vsi.idp.map.server.mapper]' package. Please check your configuration.  

那么,如何解决这个问题呢?

UPDATE 它是一个 gwt Web 应用程序,完整的错误堆栈是:
INFO: Root WebApplicationContext: initialization started Nov 23, 2015 7:12:29 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh 
INFO: Refreshing Root WebApplicationContext: startup date [Mon Nov 23 19:12:29 CST 2015]; root of context hierarchy Nov 23, 2015 7:12:29 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml] Nov 23, 2015 7:12:29 PM org.mybatis.spring.mapper.ClassPathMapperScanner doScan 
WARNING: No MyBatis mapper was found in '[com.vsi.idp.map.server.mapper]' package. Please check your configuration.Nov 23, 2015 7:12:30 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init> 
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
Module setup completed in 1698 ms 
Nov 23, 2015 7:12:30 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
INFO: Root WebApplicationContext: initialization completed in 1557 ms 

请您参考如下方法:

@MapperScan(basePackages = "com.vsi.idp.map.server.mapper") 

您可以尝试添加它!


标签:MyBatis
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号