2024年3月6日
Spring scan Author: HuiFer 源码阅读仓库: SourceHot-Spring 解析 Spring 注解形式使用有下面两种方式 通过AnnotationConfigApplicationContext参数:扫描包 通过 xml 配置context:component-scan属性base-package 1 2 AnnotationConfigApplicationContext aac = new AnnotationConfigApplicationContext("com.huifer.source.spring.ann"); 1 2 <context:component-scan base-package="com.huifer.source.spring.ann"> </context:component-scan> 目标明确开始找入口方法 Annota……
阅读全文
2024年3月6日
Spring BeanFactory Author: HuiFer 源码阅读仓库: SourceHot-spring BeanFactory 概述 org.springframework.beans.factory.BeanFactory 类图 方法列表 贴出部分代码. 仅表示方法作用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public interface BeanFactory { // 从容器中根据beanname获取 Object getBean(String name) throws BeansException; // 延迟加载对象 <T> ObjectProvider<T> getBeanProvider(Class<T> requiredType); // 是否存在beanName boolean containsBean(String name); // 这个 beanName 是否是单例的. 映射成 bean boolean isSingleton(String name) throws NoSuchBeanDefinitionException; // 是否多例. boolean isPrototype(String name) throws NoSuchBeanDefinitionException; // 类……
阅读全文
2024年3月6日
Spring SystemPropertyUtils spring 中获取系统属性的工具类 内部属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /** * * Prefix for system property placeholders: "${". * 前缀占位符 * */ public static final String PLACEHOLDER_PREFIX = "${"; /** * Suffix for system property placeholders: "}". * 后缀占位符 * */ public static final String PLACEHOLDER_SUFFIX = "}"; /** * Value separator for system property placeholders: ":". * 值分割符号 * */ public static final String VALUE_SEPARATOR = ":"; /** * 占位符解析类 */ private static final PropertyPlaceholderHelper strictHelper = new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, false);……
阅读全文
2024年3月6日
Spring StopWatch Author: HuiFer 源码阅读仓库: SourceHot-spring 全路径: org.springframework.util.StopWatch 属性 taskList: 任务信息列表 keepTaskList: 是否保留任务信息列表 startTimeMillis: 任务开始的时间 currentTaskName: 任务名称 lastTaskInfo: 任务信息 taskCount: 任务数量 totalTimeMillis: 总共花费的时间 方法 org.springframework.util.StopWatch.start(java.lang.String) 1 2 3 4 5 6 7 public void start(String taskName) throws IllegalStateException { if (this.currentTaskName != null) { throw new IllegalStateException("Can't start StopWatch: it's already running"); } this.currentTaskName = taskName; this.startTimeMillis = System.currentTimeMillis(); } org.springframework.util.StopWatch.stop 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public void stop() throws IllegalStateException { if (this.currentTaskName == null) { throw new IllegalStateException("Can't stop StopWatch: it's not……
阅读全文
2024年3月6日
SpringFactoriesLoader Author: HuiFer 源码阅读仓库: SourceHot-spring-boot 全路径 : org.springframework.core.io.support.SpringFactoriesLoader 测试类 : org.springframework.core.io.support.SpringFactoriesLoaderTests loadFactories 加载并实例化工厂 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public static <T> List<T> loadFactories(Class<T> factoryType, @Nullable ClassLoader classLoader) { Assert.notNull(factoryType, "'factoryType' must not be null"); ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { classLoaderToUse = SpringFactoriesLoader.class.getClassLoader(); } // 工厂实现类名称 List<String> factoryImplementationNames = loadFactoryNames(factoryType, classLoaderToUse); if (logger.isTraceEnabled()) { logger.trace("Loaded [" + factoryType.getName() + "] names: " + factoryImplementationNames); } List<T> result = new ArrayList<>(factoryImplementationNames.size()); for (String factoryImplementationName : factoryImplementationNames) { // 将实例化的工厂放入结果集合 result.add(instantiateFactory(factoryImplementationName, factoryType, classLoaderToUse)); } // 排序 AnnotationAwareOrderComparator.sort(result); return……
阅读全文
2024年3月6日
Spring-SimpleAliasRegistry Author: HuiFer 源码阅读仓库: huifer-spring AliasRegistry SimpleAliasRegistry继承org.springframework.core.AliasRegistry 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 public interface AliasRegistry { /** * Given a name, register an alias for it. * 别名注册 * * @param name the canonical……
阅读全文
2024年3月6日
Spring 定时任务 Author: HuiFer 源码阅读仓库: SourceHot-spring EnableScheduling 首先关注的类为启动定时任务的注解@EnableScheduling 1 2 3 4 5 6 7 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Import(SchedulingConfiguration.class) @Documented public @interface EnableScheduling { } SchedulingConfiguration 注册定时任务相关信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @Configuration @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public class SchedulingConfiguration { /** * 开启定时任务 * @return */ @Bean(name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME) @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public ScheduledAnnotationBeanPostProcessor scheduledAnnotationProcessor() { // 注册 ScheduledAnnotationBeanPostProcessor return new ScheduledAnnotationBeanPostProcessor(); } } ScheduledAnnotationBeanPostProcessor 关注 application 事件,以及 spring 生命周期……
阅读全文
2024年3月6日
Spring PropertySources Author: HuiFer 源码阅读仓库: SourceHot-spring MutablePropertySources 全路径: org.springframework.core.env.MutablePropertySources MutablePropertySources类内部存储了List<PropertySource<?>>对象,主要是针对List<PropertySource<?>> 进行的操作.换句话说就是对 list 操作……
阅读全文
2024年3月6日
Spring PropertyPlaceholderHelper 类全路径: org.springframework.util.PropertyPlaceholderHelper parseStringValue org.springframework.util.PropertyPlaceholderHelper#parseStringValue 这个方法是主要方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 protected String parseStringValue( String value, PlaceholderResolver placeholderResolver, @Nullable Set<String> visitedPlaceholders) { // 占位符所在位置 int startIndex = value.indexOf(this.placeholderPrefix); if (startIndex == -1) { return value; } // 返回值 StringBuilder result = new StringBuilder(value); while (startIndex != -1) { // 寻找结尾占位符……
阅读全文
2024年3月6日
Spring Property Author: HuiFer 源码阅读仓库: SourceHot-spring 相关类 org.springframework.beans.PropertyValues org.springframework.beans.PropertyValue org.springframework.beans.MutablePropertyValues 类图如下 在 Spring IoC 中,非 Web 工程,使用 xml 或者注解进行配置主要使用到的是 PropertyValues ,PropertyValue ,MutablePropertyValues 三个 其中 PropertyValues 是继承迭代器,具体实现在MutablePropertyValues 他们处理的对象是Propert……
阅读全文