After MyBatis and spring are integrated, the creation of the bean report is the wrong solution

Source: Internet
Author: User


Mabatis Generator Auto-generated mapper class

Package Com.aliapp.wxxd.material.service;import interfaces. Entitywrapperinterface;import Java.util.list;import org.springframework.beans.factory.annotation.Autowired; Import Org.springframework.stereotype.component;import Org.springframework.stereotype.repository;import Org.springframework.stereotype.service;import Org.springframework.web.multipart.multipartfile;import Com.aliapp.wxxd.material.entity.db.material;import Com.aliapp.wxxd.material.entity.db.materialcount;import Com.aliapp.wxxd.material.entity.db.materialcountexample;import Com.aliapp.wxxd.material.mapper.materialcountmapper;import util. Fileutil;import util.ienum.messagetypeenum;/** * * *  @author vanxd * */@Servicepublic class Materialcountmapperproxy implements materialcountmapper{//Note This interface is generated automatically, in order to make the proxy and the target interface consistent, so I also implemented it <pre name= "code "Class=" java > @AutowiredMaterialCountMapper materialcountmapper;//...
//..
}

Start Tomcat Error:

WARN [Localhost-startstop-1]-Exception encountered during context initialization-cancelling refresh Attemptorg.spring Framework.beans.factory.BeanCreationException:Error creating Bean with Name ' Materialfacade ': Injection of autowired Dependencies failed; Nested exception isorg.springframework.beans.factory.BeanCreationException:Could not autowire field: Com.aliapp.wxxd.material.service.MaterialCountMapperProxy facade. Materialfacade.materialcountmapperproxy; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [ Com.aliapp.wxxd.material.service.MaterialCountMapperProxy] 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:334)     at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1202)     at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:537)     at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean ( abstractautowirecapablebeanfactory.java:476)     at Org.springframework.beans.factory.support.abstractbeanfactory$1.getobject (abstractbeanfactory.java:303)      at Org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton ( defaultsingletonbeanregistry.java:230)     at Org.springframework.beans.factory.support.AbstractBeanFactory.doGeTbean (abstractbeanfactory.java:299)     at Org.springframework.beans.factory.support.AbstractBeanFactory.getBean (abstractbeanfactory.java:194)      at Org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons ( defaultlistablebeanfactory.java:762)     at Org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization ( abstractapplicationcontext.java:757)     at Org.springframework.context.support.AbstractApplicationContext.refresh (abstractapplicationcontext.java:480)     at Org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext ( contextloader.java:403)     at Org.springframework.web.context.ContextLoader.initWebApplicationContext (contextloader.java:306)     at org.springframework.web.context.ContextLoaderListener.contextInitialized (Contextloaderlistener.java : 106)     at org.apache.caTalina.core.StandardContext.listenerStart (standardcontext.java:4772)     at Org.apache.catalina.core.StandardContext.startInternal (standardcontext.java:5196)     at Org.apache.catalina.util.LifecycleBase.start (lifecyclebase.java:150)     at Org.apache.catalina.core.containerbase$startchild.call (containerbase.java:1409)     at Org.apache.catalina.core.containerbase$startchild.call (containerbase.java:1399)     at Java.util.concurrent.FutureTask.run (futuretask.java:262)     at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1145)     at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:615)     at Java.lang.Thread.run (thread.java:744)

。。。

。。

。。

Spring indicates that no bean of the Materialcountmapperproxy class was found, note that I added @service, and the configuration file was scanned.

Mapper Scan configuration by spring

<!--Mapper Scan configuration--><bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" ><property name= " Sqlsessionfactorybeanname "value=" sqlsessionfactory "></property><property name=" BasePackage "value=" Com.aliapp.wxxd.material.mapper "></property></bean>

After scanning, it must be that the bean is assembled in the IOC container, and it is suspected that there is an association here, so there will be an error.

Will

<span style= "FONT-SIZE:24PX;" >implements materialcountmapper</span>
Remove, TOMCAT starts normally.


However, there is no guarantee that the interface and mapper of my proxy class are consistent ...


And if my transaction is not related to this class, but also can implement this interface, Normal startup ... It's depressing.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

After MyBatis and spring are integrated, the creation of the bean report is the wrong solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.