• 自定义xml spring bean


    一. xml中bean解析过程

    扫描META-INF下面的

    spring.schemas  bean定义对应的xsd位置,在IDEA中可以辅助校验)

    spring.handlers   xmlns对应的bean具体解析器, 一般会继承NamespaceHandlerSupport,

    NSHandler下面是具体解析过程, 最终返回的结果是spring中的BeanDefinition

    参见<dubbo:config> <hsf:provider> <mvc:annotation-driven>的解析过程

    二. 注解形式的自定义bean

    BeanDefinitionRegistryPostProcessor

    mybatis中的bean注解扫描过程, ===> mapper接口为何可以使用Autowire自动注入

    扫描包下的所有类都会创建成对应的MapperFactoryBean对象,同时继承了FactoryBean, 在spring容器getBean时调用FactoryBean的getObject方法,生成mapper的proxy对象

    @Import(MapperScannerRegistrar.class)
    public @interface MapperScan

    如果使用了MapperScan,就会使用MapperScannerRegistrar.class扫描mapperScan定义的包名, 在里面创建mapper对应的MapperFactoryBean


    @Import({ AutoConfiguredMapperScannerRegistrar.class })
    @ConditionalOnMissingBean(MapperFactoryBean.class)
    public static class MapperScannerRegistrarNotFoundConfiguration

    如果没有使用MapperScan, 使用的是org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration.MapperScannerRegistrarNotFoundConfiguration上面import引入的AutoConfiguredMapperScannerRegistrar来扫描基础包名
    注意这个注解@ConditionalOnMissingBean


    resources下面的mapper.xml是什么时候加载进去的?
    MybatisAutoConfiguration里面sessionFactory初始化时 factory.setMapperLocations(this.properties.resolveMapperLocations());

  • 相关阅读:
    OpenCV使用边缘提取、腐蚀、轮廓进行车牌定位
    How To Move Or Rebuild A Lob Partition
    Hadoop入门进阶步步高(三)-配置Hadoop
    [学习笔记]整体DP
    leetcode404
    leetcode349
    leetcode383
    leetcode453
    leetcode455
    leetcode167
  • 原文地址:https://www.cnblogs.com/yszzu/p/9183240.html
Copyright © 2020-2023  润新知