Today in the integration of MyBatis process, I use scanning to scan the DAO directory Java file, but the service layer when using autowired error, but the project can run normally, here are bug!
Solution:
1. Create a annotation package
2. Define an annotation
@Retention (retentionpolicy.runtime) @Target (elementtype.type) @Documented @component public @Interface mybatismapper { default "";}
3. Configure the Mapperscannerconfigurer in Spring-mybatis.xml
<Beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer"> < Propertyname= "Basepackage"value= "Com.cyou.nad.goldlocker.dao.mybatis" /> < Propertyname= "Annotationclass"value= "Com.cyou.nad.goldlocker.annotation.MybatisMapper"/> </Bean>
4. Add annotations on the DAO layer mapper file
@MybatisMapper Public Interface Topicmapper {}
5.Service Layer Normal use
@Autowired Private Topicmapper Topicmapper;
Java Add custom annotations