3个文件,web.xml,applicationContext.xml,springmvc.xml,现在启动报错
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'homeController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xebest.service.XeUserTypeService com.xebest.controller.HomeController.xeUserTypeService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xeUserTypeServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xebest.mapper.XeUserTypeReadMapper com.xebest.service.serviceImpl.XeUserTypeServiceImpl.xeUserTypeReadMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.xebest.mapper.XeUserTypeReadMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
a

解决方案 »

  1.   

    NoSuchBeanDefinitionException: No matching bean of type [com.xebest.mapper.XeUserTypeReadMapper] 
    applicationContext.xml少一个东西,你添加一下:<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
    p:basePackage="com.xebest.mapper.XeUserTypeReadMapper" 
    p:sqlSessionFactoryBeanName="sqlSessionFactory" />如果你用不了这种表达,换成:<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.xebest.mapper.XeUserTypeReadMapper"/>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>我这边手打的,没有测试,你根据你自己的情况改一下
      

  2.   

     没有为依赖项找到[com.xebest.mapper.XeUserTypeReadMapper] 类型的匹配bean 看一下是不是mapper.xml的问题
      

  3.   

    如果按照四楼的配置,暂时是可以了,要是你以后增加一个Mapper,你的配置文件就得跟着改了,不如用springmvc的自动扫描包,这样: <!-- 自动扫描所有的Mapper接口与文件 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.xebest.mapper"></property>
    </bean>,你试试