1.Home.md

spring (由Rod Johnson创建的一个开源框架)

Spring是一个开放源代码的设计层面框架,他解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson创建。简单来说,Spring是一个分层的JavaSE/EE full-stack(一站式) 轻量级开源框架。


2.整体架构.md

架构图


3.spring组件列表.md

一、 spring核心

ImportBeanDefinitionRegistrar

解析注解,装载类到spring context


public class RpcInitConfig implements ImportBeanDefinitionRegistrar{
    
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        ClassPathScanningCandidateComponentProvider provider = getScanner();
        //设置扫描器
        provider.addIncludeFilter(new AnnotationTypeFilter(RpcClient.class));
        //扫描此包下的所有带有@RpcClient的注解的类
        Set<BeanDefinition> beanDefinitionSet = provider.findCandidateComponents("com.example.rpcclient.client");
        for (BeanDefinition beanDefinition : beanDefinitionSet){
            if (beanDefinition instanceof AnnotatedBeanDefinition){
                //获得注解上的参数信息
                AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition;
                String beanClassAllName = beanDefinition.getBeanClassName();
                Map<String, Object> paraMap = annotatedBeanDefinition.getMetadata()
                        .getAnnotationAttributes(RpcClient.class.getCanonicalName());
                //将RpcClient的工厂类注册进去
                BeanDefinitionBuilder builder = BeanDefinitionBuilder
                        .genericBeanDefinition(RpcClinetFactoryBean.class);
                //设置RpcClinetFactoryBean工厂类中的构造函数的值
                builder.addConstructorArgValue(beanClassAllName);
                builder.getBeanDefinition().setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
                //将其注册进容器中
                registry.registerBeanDefinition(
                        beanClassAllName ,
                        builder.getBeanDefinition());
            }
        }
    }
    //允许Spring扫描接口上的注解
    protected ClassPathScanningCandidateComponentProvider getScanner() {
        return new ClassPathScanningCandidateComponentProvider(false) {
            @Override
            protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
                return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent();
            }
        };
    }
}


AnnotationInjectedBeanPostProcessor

public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBeanPostProcessor<Reference> {
    /**
     * The bean name of {@link ReferenceAnnotationBeanPostProcessor}
     */
    public static final String BEAN_NAME = "referenceAnnotationBeanPostProcessor";


    @Override
    protected Object doGetInjectedBean(Reference reference, Object bean, String beanName, Class<?> injectedType,
                                       InjectionMetadata.InjectedElement injectedElement) throws Exception {
        return ClientStartHelper.getInstance().createProxy(injectedType, reference.type(), reference.timeout(), reference.tag());
    }


    /**
     * 相同配置的reference 的cacheKey相同,只缓存一个proxy实例。
     */
    @Override
    protected String buildInjectedObjectCacheKey(Reference reference, Object bean, String beanName, Class<?> injectedType, InjectionMetadata.InjectedElement injectedElement) {
        Joiner joiner = Joiner.on(".").useForNull("null");
        return joiner.join(injectedType.getName(), reference.type().getCode(), reference.timeout(), reference.tag());
    }

    @Override
    public void destroy() throws Exception {
        super.destroy();

    }
}

参考资料:

动态注册bean
springbean过程

Spring aop

编程式的创建Aop代理之ProxyFactory

使用ApplicationEvent和Listener快速实现业务解耦

Spring 提供了以下的标准事件

二、spring生命周期

Spring Bean生命周期

AutowireCapableBeanFactory

SmartInitializingSingleton

SmartLifecycle

Spring SmartLifecycle 在容器所有bean加载和初始化完毕执行

Spring 刷新应用上下文refreshContext

https://segmentfault.com/a/1190000020494692?utm_source=tag-newest

三、工具类

JamonPerformanceMonitorInterceptor

spring线程池(同步、异步),SimpleAsyncTaskExecutor

线程池总结

Spring Retry BackOff

Spring异常重试框架Spring Retry

@Value

Spring @Value的$和#用法区别

HandlerMethodArgumentResolver

SpringBoot无法启动,Process finished with exit code 0

1、排查yml和properties文件是否配置错误

2、排查POM引入的包

Spring MVC常用注解@PathVariable、@RequestHeader、@CookieValue、@RequestParam、@RequestBody、@SessionAttributes、@ModelAttribute

Spring注解@Primary的意思

@Primary:在众多相同的Bean中,优先使用@Primary注解的Bean。

这个和@Qualifier有点区别,@Qualifier指的是使用哪个Bean进行注入。

SprintObjenesis

ListenableFuture

UnsafeUtils

SingletonSupplier

cglib

GenericConverter

ClassPathResource ,FileSystemResource ,FileUrlResource

LogFormatUtils,CompositeLog

Deserializer,Serializer

StylerUtils

StandardClassMetadata, Constants

Base64Utils

SpringBootVFS

AntPathMatcher

AntPathMatcher antPathMatcher = new AntPathMatcher();

antPathMatcher.isPattern("/user/001");// 返回 false
antPathMatcher.isPattern("/user/*"); // 返回 true
antPathMatcher.match("/user/001","/user/001");// 返回 true
antPathMatcher.match("/user/*","/user/001");// 返回 true
antPathMatcher.matchStart("/user/*","/user/001"); // 返回 true
antPathMatcher.matchStart("/user/*","/user"); // 返回 true
antPathMatcher.matchStart("/user/*","/user001"); // 返回 false
antPathMatcher.extractPathWithinPattern("uc/profile*","uc/profile.html"); // 返回 profile.html
antPathMatcher.combine("uc/*.html","uc/profile.html"); // uc/profile.html

4.spring aop.md

拦截打印参数时间

https://juejin.im/post/5cc68dee6fb9a0325031bd73


4.spring 配置.md

  • 配置 spring.datasource.initialize=false 关闭springboot数据源初始化功能(推荐)

  • banner.txt


Copyright © 2018 INSTALL.REN