SpringBoot源码
w011m
这个作者很懒,什么都没留下…
展开
-
SpringBoot 源码阅读(18):设计模式总结
设计模式在源码阅读过程中看到了各种设计模式,在此总结(这里不对各种设计模式多做介绍)。工厂模式工厂模式最典型的就是BeanFactory,通过bean名称我们可以获取bean实例,见博客。代理模式AOP的实现本质即使代理模式,通过JDK或CGLIB新建一个类代理原来的类,在保证原来类的功能的基础上进行增强。见博客。适配器模式在AOP源码中,我们看到通过适配器将没有实现MethodInterceptor接口的Advisor转换成方法拦截器,从而最后获取一条拦截链,即使用了适配器模式。见博客。观原创 2020-08-31 20:01:51 · 1071 阅读 · 1 评论 -
SpringBoot 源码阅读(17):AOP
AOPAOP自动配置如下:@Configuration@ConditionalOnClass({EnableAspectJAutoProxy.class, Aspect.class, Advice.class, AnnotatedElement.class})@ConditionalOnProperty( prefix = "spring.aop", name = {"auto"}, havingValue = "true", matchIfMissing = tru原创 2020-08-29 19:36:08 · 339 阅读 · 0 评论 -
SpringBoot 源码阅读(16):createBean
createBean@Overrideprotected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) throws BeanCreationException { if (logger.isTraceEnabled()) { logger.trace("Creating instance of bean '" + beanName + "'"); } RootBea原创 2020-08-25 11:48:12 · 285 阅读 · 0 评论 -
SpringBoot 源码阅读(13):getBean
getBean通过getBean的源码可以了解Spring Bean的加载过程AbstractApplicationContext:@Overridepublic Object getBean(String name) throws BeansException { assertBeanFactoryActive(); return getBeanFactory().getBean(name);}AbstractBeanFactory:@Overridepublic Object ge原创 2020-08-10 11:03:00 · 270 阅读 · 0 评论 -
SpringBoot 源码阅读(15):PostProcessor
PostProcessor后处理器是Spring功能扩展很重要的一部分,在源码中很多地方都可以见到,在此做下总结。BeanFactoryPostProcessor应用于刷新上下文时对BeanFactory的扩展可细分为BeanDefinitionRegistryPostProcessor与BeanFactoryPostProcessor,BeanDefinitionRegistryPostProcessor继承自BeanFactoryPostProcessor。@FunctionalInterf原创 2020-08-08 12:03:51 · 239 阅读 · 1 评论 -
SpringBoot 源码阅读(14):FactoryBean与BeanFactory
FactoryBeanFactoryBean为Spring提供的一个接口。直接尝试获取该类的实例并不会直接获取该类的实例,而是获得通过getObject获得的对象,即加工后的对象,该实例为一个工厂。想获得该工厂的实例,需要在bean名称前加前缀“&”。public interface FactoryBean<T> { @Nullable T getObject() throws Exception; @Nullable Class<?> getObject原创 2020-08-07 15:42:24 · 455 阅读 · 0 评论 -
SpringBoot 源码阅读(10):AutoConfigurationImportSelector(自动配置)
AutoConfigurationImportSelectorpublic class AutoConfigurationImportSelector implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered { …………}该类为通过注解@EnableAutoConfiguration引入的类(见博客),原创 2020-08-07 11:20:31 · 405 阅读 · 1 评论 -
SpringBoot 源码阅读(9):ConfigurationClassPostProcessor与@ComponentScan、@Import
ConfigurationClassPostProcessor现在看下Spring Boot如何解析两个注解:@EnableAutoConfiguration@ComponentScanMainApplication是一个配置类(@SpringBootConfiguration),那么不妨猜测是在解析配置类时对这两个注解进行的解析,相关的类为ConfigurationClassPostProcessor。注册在AnnotationConfigServletWebServerApplication原创 2020-08-03 10:21:46 · 198 阅读 · 0 评论 -
SpringBoot 源码阅读(8):refreshContext
refreshContextprivate void refreshContext(ConfigurableApplicationContext context) { refresh(context); if (this.registerShutdownHook) { try { context.registerShutdownHook(); } catch (AccessControlException ex) { // Not allowed in some environ原创 2020-07-30 11:39:45 · 306 阅读 · 1 评论 -
SpringBoot 源码阅读(12):@Conditional
@Conditional条件注解:@Target({ElementType.TYPE, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Conditional { /** * All {@link Condition Conditions} that must {@linkplain Condition#matches match} * in order for th原创 2020-07-27 22:29:35 · 81 阅读 · 0 评论 -
SpringBoot 源码阅读(11):@Component(@Configuration @Service @Repository @Controller)
@Component该注解代表该类为Spring的组件:@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Indexedpublic @interface Component { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean i原创 2020-07-27 21:30:00 · 164 阅读 · 0 评论 -
SpringBoot 源码阅读(5):@ComponentScan
@ComponentScan@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })@Retention(RetentionPolicy.RUNTIME)@Target(Ele原创 2020-07-27 11:22:23 · 259 阅读 · 0 评论 -
SpringBoot 源码阅读(4):@EnableAutoConfiguration
@EnableAutoConfiguration该注解用于自动配置,而自动配置是大部分人使用SpringBoot开发的主要原因。@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@AutoConfigurationPackage@Import(AutoConfigurationImportSelector.class)public @interface EnableAutoConf原创 2020-07-27 11:17:32 · 278 阅读 · 0 评论 -
SpringBoot 源码阅读(7):prepareContext
prepareContextprivate void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) { //设置环境 context.setE原创 2020-07-22 11:33:37 · 134 阅读 · 0 评论 -
SpringBoot 源码阅读(6):createApplicationContext
createApplicationContext默认启动创建应用上下文AnnotationConfigServletWebServerApplicationContext:protected ConfigurableApplicationContext createApplicationContext() { Class<?> contextClass = this.applicationContextClass; //根据web应用类型寻找相应上下文的Class if (cont原创 2020-07-22 10:37:27 · 285 阅读 · 0 评论 -
SpringBoot 源码阅读(1):启动
@SpringBootApplication首先看下其源码@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExclud原创 2020-07-21 16:51:30 · 175 阅读 · 0 评论 -
SpringBoot 源码阅读(3):WebApplicationType
WebApplicationType为一个枚举类,主要有三个枚举值:public enum WebApplicationType{ /** * The application should not run as a web application and should not start an * embedded web server. */ NONE, /** * The application should run as a servlet-based web appli原创 2020-07-21 16:18:01 · 463 阅读 · 0 评论 -
SpringBoot 源码阅读(2):ResourceLoader与Resource
ResourceLoader与ResourceResourceLoader顾名思义,用于加载资源,是org.springframework.core.io提供的一个借口:public interface ResourceLoader { /** Pseudo URL prefix for loading from the class path: "classpath:". */ String CLASSPATH_URL_PREFIX = ResourceUtils.CLASSPATH_URL_PR原创 2020-07-21 15:54:55 · 328 阅读 · 0 评论