Spring源码学习01

2020年6月29日

  1. 配置类 注解@Configruation

  2. 注解扫描,通过注解@ComponentScans,扫描指定的包.

    package com.wzl.yanyan.spring01;
    
    import com.wzl.yanyan.Person;
    import com.wzl.yanyan.spring01.filter.MyFilterType;
    import com.wzl.yanyan.spring01.service.SpringService;
    import org.springframework.context.annotation.*;
    import org.springframework.stereotype.Controller;
    
    @Configuration
    //@ComponentScan(value = "com.wzl.yanyan",
    //        excludeFilters ={@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class})} )
    //
    @ComponentScans(value = {
            @ComponentScan(value = "com.wzl.yanyan",
            includeFilters ={
    //                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class}),
    //                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {SpringService.class})} ,
                    @ComponentScan.Filter(type = FilterType.CUSTOM,value = {MyFilterType.class})},
            useDefaultFilters = false)})
    // 查看注解,以及用法
    // 使用 includeFilters,或者 excludeFilters,
    public class MainConfig {
    
        /**
         *  默认方法名称作为ID
         * @return Person
         */
        @Bean("persons")
        public Person personConfig(){
            return new Person("config",21);
        }
    }
    
  3. bean的作用域,如果默认是单例的.会直接创建Bean

  4. 懒加载是针对 singleton

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容