zoukankan      html  css  js  c++  java
  • 自定义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());

  • 相关阅读:
    python socket 二进制
    全面介绍内存管理机制
    glog修改
    mysql c api
    http twisted
    IOCP 模型1
    IOCP 模型2 AcceptEx
    python
    Python Twisted
    Java 拾遗
  • 原文地址:https://www.cnblogs.com/yszzu/p/9183240.html
Copyright © 2011-2022 走看看