开发者社区> 问答> 正文

mybatis的MapperScannerConfigurer为什么不能用spr?报错

然后结果是,报错!提示${ccc}找不到,然后我把${ccc}挪到其他的bean,能读出值,证明不是*.properties文件的问题。


其中public class MapperScannerConfigurer implements BeanDefinitionRegistryPostProcessor, InitializingBean, ApplicationContextAware, BeanNameAware{

}


是因为MapperScannerConfigurer 继承的东西影响了占位符的注入吗?

展开
收起
爱吃鱼的程序员 2020-06-08 18:10:36 603 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    好问题。MapperScannerConfigurer确实特殊,在该类被加载时,Spring还未处理placeholder,具体详见 MapperScannerConfigurer的源码说明,

    Thisconfigurerenablesautowireforallthebeansthatitcreatessothattheyare
     *automaticallyautowiredwiththeproper{@codeSqlSessionFactory}or{@codeSqlSessionTemplate}.
     *Ifthereismorethanone{@codeSqlSessionFactory}intheapplication,however,autowiring
     *cannotbeused.Inthiscaseyoumustexplicitlyspecifyeitheran{@codeSqlSessionFactory}or
     *an{@codeSqlSessionTemplate}touseviathe<em>beanname</em>properties .Beannamesareused
     *ratherthanactualobjectsbecauseSpringdoesnotinitializepropertyplaceholdersuntilafter
     *thisclassisprocessed. 

    是bean的初始化顺序影响了?? <beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><propertyname="systemPropertiesModeName"value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/><propertyname="ignoreResourceNotFound"value="false"/><propertyname="locations"><list><value>classpath*:/properties/dataStorage.properties</value><value>classpath*:/properties/application.properties</value><value>classpath*:/properties/telephone.properties</value></list></property></bean>



    2020-06-08 18:10:55
    赞同 1 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载