网络应用启动警告:在...中找不到MyBatis映射器,请检查您的配置

时间:2015-11-23 09:44:42

标签: spring mybatis

我的配置是:

spring-4.2.3
mybatis-3.3.0
mybatis-spring-1.2.3

mapper看起来像:

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

2 个答案:

答案 0 :(得分:3)

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

您可以尝试添加它!

答案 1 :(得分:0)

您是否在applicationContext.xml中定义了MapperScannerConfigurer?如果是,请删除它。

我在applicationContext.xml中有以下配置,当我删除它时,警告就消失了。

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.james.reg.mapper" />
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>