<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Clazz on 知识铺的博客</title>
    <link>https://index.zshipu.com/geek/tags/clazz/</link>
    <description>Recent content in Clazz on 知识铺的博客</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-CN</language>
    <lastBuildDate>Wed, 06 Mar 2024 13:23:00 +0000</lastBuildDate>
    <atom:link href="https://index.zshipu.com/geek/tags/clazz/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Spring-Printer</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-Printer/</link>
      <pubDate>Wed, 06 Mar 2024 13:23:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-Printer/</guid>
      <description>Spring Printer 类全路径: org.springframework.format.Printer 类作用: 对象转换成字符串 1 2 3 4 5 6 7 8 9 10 11 12 13 @FunctionalInterface public interface Printer&amp;lt;T&amp;gt; { /** * Print the object of type T for display. * 打印对象 * @param object the instance to print * @param locale the current user locale * @return the printed text string */ String print(T object, Locale locale); }</description>
    </item>
    <item>
      <title>Spring-Parser</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-Parser/</link>
      <pubDate>Wed, 06 Mar 2024 13:22:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-Parser/</guid>
      <description>Spring Parser 类全路径: org.springframework.format.Parser 类作用: 字符串准换成 java 对象 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @FunctionalInterface public interface Parser&amp;lt;T&amp;gt; { /** * Parse a text String to produce a T. * 将字符串转换成对象 * @param text the text string * @param locale the current user locale * @return an instance of T * @throws ParseException when a parse exception occurs in a java.text parsing library * @throws IllegalArgumentException when a parse exception occurs */ T parse(String text, Locale locale) throws ParseException; } 类图</description>
    </item>
    <item>
      <title>Spring-Formatter</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-Formatter/</link>
      <pubDate>Wed, 06 Mar 2024 13:21:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-Formatter/</guid>
      <description>Spring Formatter 类全路径: org.springframework.format.Formatter 1 2 3 public interface Formatter&amp;lt;T&amp;gt; extends Printer&amp;lt;T&amp;gt;, Parser&amp;lt;T&amp;gt; { } 该接口继承了 printer 和 parser 两个接口. 比较常见的有: DateFormatter 就是继承这个接口.</description>
    </item>
    <item>
      <title>Spring-AnnotationFormatterFactory</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-AnnotationFormatterFactory/</link>
      <pubDate>Wed, 06 Mar 2024 13:20:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/format/Spring-AnnotationFormatterFactory/</guid>
      <description>Spring AnnotationFormatterFactory 类全路径: org.springframework.format.AnnotationFormatterFactory 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 public interface AnnotationFormatterFactory&amp;lt;A extends Annotation&amp;gt; { /** * The types of fields that may be annotated with the &amp;amp;lt;A&amp;amp;gt; annotation. * 字段类型 */ Set&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; getFieldTypes(); /** * Get the Printer to print the value of a field of {@code fieldType} annotated with * {@code annotation}. * &amp;lt;p&amp;gt;If the type T the printer accepts is not assignable to {@code fieldType}, a * coercion from {@code fieldType} to T will be attempted before the Printer is invoked. * 通过注解和字段类型获取输出接口 * @param annotation the</description>
    </item>
    <item>
      <title>Spring-scan</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-scan/</link>
      <pubDate>Wed, 06 Mar 2024 13:16:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-scan/</guid>
      <description>Spring scan Author: HuiFer 源码阅读仓库: SourceHot-Spring 解析 Spring 注解形式使用有下面两种方式 通过AnnotationConfigApplicationContext参数:扫描包 通过 xml 配置context:component-scan属性base-package 1 2 AnnotationConfigApplicationContext aac = new AnnotationConfigApplicationContext(&amp;#34;com.huifer.source.spring.ann&amp;#34;); 1 2 &amp;lt;context:component-scan base-package=&amp;#34;com.huifer.source.spring.ann&amp;#34;&amp;gt; &amp;lt;/context:component-scan&amp;gt; 目标明确开始找入口方法 Annota</description>
    </item>
    <item>
      <title>Spring-beanFactory</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-beanFactory/</link>
      <pubDate>Wed, 06 Mar 2024 13:15:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-beanFactory/</guid>
      <description>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; // 延迟加载对象 &amp;lt;T&amp;gt; ObjectProvider&amp;lt;T&amp;gt; getBeanProvider(Class&amp;lt;T&amp;gt; requiredType); // 是否存在beanName boolean containsBean(String name); // 这个 beanName 是否是单例的. 映射成 bean boolean isSingleton(String name) throws NoSuchBeanDefinitionException; // 是否多例. boolean isPrototype(String name) throws NoSuchBeanDefinitionException; // 类</description>
    </item>
    <item>
      <title>Spring-SystemPropertyUtils</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-SystemPropertyUtils/</link>
      <pubDate>Wed, 06 Mar 2024 13:14:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-SystemPropertyUtils/</guid>
      <description>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: &amp;#34;${&amp;#34;. * 前缀占位符 * */ public static final String PLACEHOLDER_PREFIX = &amp;#34;${&amp;#34;; /** * Suffix for system property placeholders: &amp;#34;}&amp;#34;. * 后缀占位符 * */ public static final String PLACEHOLDER_SUFFIX = &amp;#34;}&amp;#34;; /** * Value separator for system property placeholders: &amp;#34;:&amp;#34;. * 值分割符号 * */ public static final String VALUE_SEPARATOR = &amp;#34;:&amp;#34;; /** * 占位符解析类 */ private static final PropertyPlaceholderHelper strictHelper = new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, false);</description>
    </item>
    <item>
      <title>Spring-StopWatch</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-StopWatch/</link>
      <pubDate>Wed, 06 Mar 2024 13:13:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-StopWatch/</guid>
      <description>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(&amp;#34;Can&amp;#39;t start StopWatch: it&amp;#39;s already running&amp;#34;); } 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(&amp;#34;Can&amp;#39;t stop StopWatch: it&amp;#39;s not</description>
    </item>
    <item>
      <title>Spring-SpringFactoriesLoader</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-SpringFactoriesLoader/</link>
      <pubDate>Wed, 06 Mar 2024 13:12:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-SpringFactoriesLoader/</guid>
      <description>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 &amp;lt;T&amp;gt; List&amp;lt;T&amp;gt; loadFactories(Class&amp;lt;T&amp;gt; factoryType, @Nullable ClassLoader classLoader) { Assert.notNull(factoryType, &amp;#34;&amp;#39;factoryType&amp;#39; must not be null&amp;#34;); ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { classLoaderToUse = SpringFactoriesLoader.class.getClassLoader(); } // 工厂实现类名称 List&amp;lt;String&amp;gt; factoryImplementationNames = loadFactoryNames(factoryType, classLoaderToUse); if (logger.isTraceEnabled()) { logger.trace(&amp;#34;Loaded [&amp;#34; + factoryType.getName() + &amp;#34;] names: &amp;#34; + factoryImplementationNames); } List&amp;lt;T&amp;gt; result = new ArrayList&amp;lt;&amp;gt;(factoryImplementationNames.size()); for (String factoryImplementationName : factoryImplementationNames) { // 将实例化的工厂放入结果集合 result.add(instantiateFactory(factoryImplementationName, factoryType, classLoaderToUse)); } // 排序 AnnotationAwareOrderComparator.sort(result); return</description>
    </item>
    <item>
      <title>Spring-SimpleAliasRegistry</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-SimpleAliasRegistry/</link>
      <pubDate>Wed, 06 Mar 2024 13:11:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-SimpleAliasRegistry/</guid>
      <description>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</description>
    </item>
    <item>
      <title>Spring-Scheduling</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Scheduling/</link>
      <pubDate>Wed, 06 Mar 2024 13:10:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Scheduling/</guid>
      <description>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 生命周期</description>
    </item>
    <item>
      <title>Spring-PropertySources</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-PropertySources/</link>
      <pubDate>Wed, 06 Mar 2024 13:09:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-PropertySources/</guid>
      <description>Spring PropertySources Author: HuiFer 源码阅读仓库: SourceHot-spring MutablePropertySources 全路径: org.springframework.core.env.MutablePropertySources MutablePropertySources类内部存储了List&amp;lt;PropertySource&amp;lt;?&amp;gt;&amp;gt;对象,主要是针对List&amp;lt;PropertySource&amp;lt;?&amp;gt;&amp;gt; 进行的操作.换句话说就是对 list 操作</description>
    </item>
    <item>
      <title>Spring-PropertyPlaceholderHelper</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-PropertyPlaceholderHelper/</link>
      <pubDate>Wed, 06 Mar 2024 13:08:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-PropertyPlaceholderHelper/</guid>
      <description>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&amp;lt;String&amp;gt; visitedPlaceholders) { // 占位符所在位置 int startIndex = value.indexOf(this.placeholderPrefix); if (startIndex == -1) { return value; } // 返回值 StringBuilder result = new StringBuilder(value); while (startIndex != -1) { // 寻找结尾占位符</description>
    </item>
    <item>
      <title>Spring-Property</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Property/</link>
      <pubDate>Wed, 06 Mar 2024 13:07:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Property/</guid>
      <description>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</description>
    </item>
    <item>
      <title>Spring-OrderUtils</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-OrderUtils/</link>
      <pubDate>Wed, 06 Mar 2024 13:06:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-OrderUtils/</guid>
      <description>Spring OrderUtils Author: HuiFer 源码阅读仓库: SourceHot-Spring org.springframework.core.annotation.OrderUtils主要方法如下 getOrder getPriority 测试类org.springframework.core.annotation.OrderUtilsTests 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20</description>
    </item>
    <item>
      <title>Spring-OrderComparator</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-OrderComparator/</link>
      <pubDate>Wed, 06 Mar 2024 13:05:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-OrderComparator/</guid>
      <description>Spring OrderComparator Author: HuiFer 源码阅读仓库: SourceHot-Spring 1 2 3 4 5 6 7 8 9 10 11 12 13 14 private int doCompare(@Nullable Object o1, @Nullable Object o2, @Nullable OrderSourceProvider sourceProvider) { boolean p1 = (o1 instanceof PriorityOrdered); boolean p2 = (o2 instanceof PriorityOrdered); if (p1 &amp;amp;&amp;amp; !p2) { return -1; } else if (p2 &amp;amp;&amp;amp; !p1) { return 1; } int i1 = getOrder(o1, sourceProvider); int i2 = getOrder(o2, sourceProvider); // 对比两个Order值得大小返回 return Integer.compare(i1, i2); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 private int getOrder(@Nullable Object obj, @Nullable OrderSourceProvider sourceProvider) { Integer order = null; if (obj != null &amp;amp;&amp;amp; sourceProvider</description>
    </item>
    <item>
      <title>Spring-MultiValueMap</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-MultiValueMap/</link>
      <pubDate>Wed, 06 Mar 2024 13:04:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-MultiValueMap/</guid>
      <description>Spring MultiValueMap Author: HuiFer 源码阅读仓库: SourceHot-spring 类路径: org.springframework.util.MultiValueMap 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 public interface MultiValueMap&amp;lt;K, V&amp;gt; extends Map&amp;lt;K, List&amp;lt;V&amp;gt;&amp;gt; { /** * 获取value的第一 */ @Nullable V getFirst(K key); /** * 添加元素 */ void add(K key, @Nullable V value); /** * 添加所有元素 */ void addAll(K key, List&amp;lt;? extends V&amp;gt; values); /** * 添加要给 {@link MultiValueMap} 对象 */ void addAll(MultiValueMap&amp;lt;K, V&amp;gt; values); default void addIfAbsent(K key, @Nullable V value) {</description>
    </item>
    <item>
      <title>Spring-MethodOverride</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-MethodOverride/</link>
      <pubDate>Wed, 06 Mar 2024 13:03:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-MethodOverride/</guid>
      <description>Spring MethodOverride Author: HuiFer 源码阅读仓库: SourceHot-spring org.springframework.beans.factory.support.MethodOverride org.springframework.beans.factory.support.LookupOverride org.springframework.beans.factory.support.ReplaceOverride org.springframework.beans.factory.support.MethodOverrides MethodOverride MethodOverride 方法重载类 在MethodOverride定义了下面三个属性 方法名称 是否重载 源 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public abstract class MethodOverride implements BeanMetadataElement { /** * 方法名称 */ private final String methodName; /** * 是否重载 */ private boolean overloaded = true; /** * 源 */ @Nullable private Object source; } 定义了一个抽象方法, 交由子类实现 1 public abstract boolean matches(Method method); 类图 在 Spring 中</description>
    </item>
    <item>
      <title>Spring-Metadata</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Metadata/</link>
      <pubDate>Wed, 06 Mar 2024 13:02:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Metadata/</guid>
      <description>Spring 元信息 Author: HuiFer 源码阅读仓库: SourceHot-Spring ClassMetadata 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 69 70 71 72 73 74 75 76 77 public interface ClassMetadata { /** * 类名 */ String getClassName(); /** * 是否是接口 */ boolean isInterface(); /** * 是否是注解 */ boolean isAnnotation(); /** * 是否是超类 */ boolean isAbstract(); /** * 是否允许创</description>
    </item>
    <item>
      <title>Spring-MessageSource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-MessageSource/</link>
      <pubDate>Wed, 06 Mar 2024 13:01:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-MessageSource/</guid>
      <description>Spring MessageSource Author: HuiFer 源码阅读仓库: SourceHot-Spring 初始化入口 org.springframework.context.support.AbstractApplicationContext.refresh方法有initMessageSource()方法进行了MessageSource初始化 1 2 3 4 5 6 7 8 9 10</description>
    </item>
    <item>
      <title>Spring-Import</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Import/</link>
      <pubDate>Wed, 06 Mar 2024 13:00:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Import/</guid>
      <description>Spring Import Author: HuiFer 源码阅读仓库: SourceHot-spring 分析 org.springframework.context.annotation.Import 1 2 3 4 5 6 7 8 9 10 11 12 13 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Import { /** * {@link Configuration @Configuration}, {@link ImportSelector}, * {@link ImportBeanDefinitionRegistrar}, or regular component classes to import. * * 需要导入的类 */ Class&amp;lt;?&amp;gt;[] value(); } ImportBeanDefinitionRegistrar 注册 Import Bean org.springframework.context.annotation.ImportBeanDefinitionRegistrar 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public interface ImportBeanDefinitionRegistrar { /** * Register bean definitions as necessary based on the given annotation metadata of * the importing {@code @Configuration} class. * &amp;lt;p&amp;gt;Note that {@link BeanDefinitionRegistryPostProcessor} types may &amp;lt;em&amp;gt;not&amp;lt;/em&amp;gt; be * registered here, due to lifecycle constraints related to {@code @Configuration} * class processing. * * 对impor</description>
    </item>
    <item>
      <title>Spring-EntityResolver</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-EntityResolver/</link>
      <pubDate>Wed, 06 Mar 2024 12:59:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-EntityResolver/</guid>
      <description>EntityResolver Author: HuiFer 源码阅读仓库: huifer-spring 源码路径: org.xml.sax.EntityResolver,非 Spring 类 DelegatingEntityResolver#resolveEntity org.springframework.beans.factory.xml.DelegatingEntityResolver.resolveEntity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 @Override @Nullable public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws SAXException, IOException { if (systemId != null) { if (systemId.endsWith(DTD_SUFFIX)) { return this.dtdResolver.resolveEntity(publicId, systemId); } else if (systemId.endsWith(XSD_SUFFIX)) { return this.schemaResolver.resolveEntity(publicId, systemId); } } // Fall back to the parser&amp;#39;s default behavior. return null; } 上述这段代码是针对 xml 进行校验 1 2 3 &amp;lt;beans xmlns:xsi=&amp;#34;http://www.w3.org/2001/XMLSchema-instance&amp;#34; xmlns=&amp;#34;http://www.springframework.org/schema/beans&amp;#34; xsi:schemaLocation=&amp;#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&amp;#34;&amp;gt; 如上所示以.x</description>
    </item>
    <item>
      <title>Spring-DefaultSingletonBeanRegistry</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-DefaultSingletonBeanRegistry/</link>
      <pubDate>Wed, 06 Mar 2024 12:58:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-DefaultSingletonBeanRegistry/</guid>
      <description>DefaultSingletonBeanRegistry Author: HuiFer 源码阅读仓库: SourceHot-Spring 源码路径: org.springframework.beans.factory.support.DefaultSingletonBeanRegistry 官方提供的测试类: org.springframework.beans.factory.support.DefaultSingletonBeanRegistryTests 类图 注册方法解析 从名字可以看出这是一个单例对象的注册类 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton 测试用例出发 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 @Test public void testSingletons() { DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry(); TestBean tb = new TestBean(); beanRegistry.registerSingleton(&amp;#34;tb&amp;#34;, tb); assertSame(tb, beanRegistry.getSingleton(&amp;#34;tb&amp;#34;)); TestBean tb2 = (TestBean) beanRegistry.getSingleton(&amp;#34;tb2&amp;#34;, new ObjectFactory&amp;lt;Object&amp;gt;() { @Override public Object getObject() throws BeansException { return new TestBean(); } }); assertSame(tb2, beanRegistry.getSingleton(&amp;#34;tb2&amp;#34;)); assertSame(tb, beanRegistry.getSingleton(&amp;#34;tb&amp;#34;)); assertSame(tb2, beanRegistry.getSingleton(&amp;#34;tb2&amp;#34;)); assertEquals(2, beanRegistry.getSingletonCount()); String[] names = beanRegistry.getSingletonNames();</description>
    </item>
    <item>
      <title>Spring-Custom-label-resolution</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Custom-label-resolution/</link>
      <pubDate>Wed, 06 Mar 2024 12:57:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Custom-label-resolution/</guid>
      <description>Spring 自定义标签解析 Author: HuiFer 源码阅读仓库: SourceHot-Spring 与自定义标签解析相关的类 org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser org.springframework.beans.factory.xml.NamespaceHandlerSupport 开始源码之前先搭建一个环境 环境搭建 创建对象 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public class UserXtd { private String userName; private String emailAddress; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } } 创建 xsd 文件 1 2 3 4 5 6 7 8 9 10 11 12 13 &amp;lt;?xml version=&amp;#34;1.0&amp;#34; encoding=&amp;#34;UTF-8&amp;#34; ?&amp;gt; &amp;lt;schema xmlns=&amp;#34;http://www.w3.org/2001/XMLSchema&amp;#34;</description>
    </item>
    <item>
      <title>Spring-Custom-attribute-resolver</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Custom-attribute-resolver/</link>
      <pubDate>Wed, 06 Mar 2024 12:56:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Custom-attribute-resolver/</guid>
      <description>Spring 自定义属性解析器 Author: HuiFer 源码阅读仓库: SourceHot-Spring 用例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 &amp;lt;?xml version=&amp;#34;1.0&amp;#34; encoding=&amp;#34;UTF-8&amp;#34;?&amp;gt; &amp;lt;beans xmlns:xsi=&amp;#34;http://www.w3.org/2001/XMLSchema-instance&amp;#34; xmlns=&amp;#34;http://www.springframework.org/schema/beans&amp;#34; xsi:schemaLocation=&amp;#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&amp;#34;&amp;gt; &amp;lt;bean class=&amp;#34;org.springframework.beans.factory.config.CustomEditorConfigurer&amp;#34;&amp;gt; &amp;lt;property name=&amp;#34;propertyEditorRegistrars&amp;#34;&amp;gt; &amp;lt;list&amp;gt; &amp;lt;bean class=&amp;#34;com.huifer.source.spring.bean.DatePropertyRegister&amp;#34;/&amp;gt; &amp;lt;/list&amp;gt; &amp;lt;/property&amp;gt; &amp;lt;property name=&amp;#34;customEditors&amp;#34;&amp;gt; &amp;lt;map&amp;gt; &amp;lt;entry key=&amp;#34;java.util.Date&amp;#34; value=&amp;#34;com.huifer.source.spring.bean.DatePropertyEditor&amp;#34;&amp;gt; &amp;lt;/entry&amp;gt; &amp;lt;/map&amp;gt; &amp;lt;/property&amp;gt; &amp;lt;/bean&amp;gt; &amp;lt;bean id=&amp;#34;apple&amp;#34; class=&amp;#34;com.huifer.source.spring.bean.Apple&amp;#34;&amp;gt; &amp;lt;property name=&amp;#34;date&amp;#34; value=&amp;#34;2020-01-01 01:01:01&amp;#34;/&amp;gt; &amp;lt;/bean&amp;gt; &amp;lt;/beans&amp;gt; 1 2 3 4 5 6 7 8 public class DatePropertyRegister implements PropertyEditorRegistrar { @Override public void registerCustomEditors(PropertyEditorRegistry registry) { registry.registerCustomEditor(Date.class, new CustomDateEditor( new SimpleDateFormat(&amp;#34;yyyy-MM-dd&amp;#34;), true) ); } } 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 public class DatePropertyEditor extends PropertyEditorSupport {</description>
    </item>
    <item>
      <title>Spring-Conditional</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Conditional/</link>
      <pubDate>Wed, 06 Mar 2024 12:55:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-Conditional/</guid>
      <description>Spring Conditional Author: HuiFer 源码阅读仓库: SourceHot-spring Conditional 1 2 3 4 5 6 7 8 9 10 11 @Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Conditional { /** * 多个匹配器接口 */ Class&amp;lt;? extends Condition&amp;gt;[] value(); } Condition @FunctionalInterface public interface Condition { /** * 匹配,如果匹配返回true进行初始化,返回false跳过初始化 */ boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata); } ConditionContext 上下文 AnnotatedTypeMetadata 注解信息 ConditionContext public interface ConditionContext { /** * bean的定义 */ BeanDefinitionRegistry getRegistry(); /** * bean 工厂 */ @Nullable ConfigurableListableBeanFactory getBeanFactory(); /** * 环境 */ Environment getEnvironment(); /** * 资</description>
    </item>
    <item>
      <title>Spring-BeanNameGenerator</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanNameGenerator/</link>
      <pubDate>Wed, 06 Mar 2024 12:54:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanNameGenerator/</guid>
      <description>Spring BeanNameGenerator Author: HuiFer 源码阅读仓库: SourceHot-spring org.springframework.beans.factory.support.BeanNameGenerator 方法用来生成 beanName 1 2 3 4 5 6 7 8 9 10 11 12 13 public interface BeanNameGenerator { /** * Generate a bean name for the given bean definition. * 生成 beanName * @param definition the bean definition to generate a name for * @param registry the bean definition registry that the given definition * is supposed to be registered with * @return the generated bean name */ String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry); } DefaultBeanNameGenerator org.springframework.beans.factory.support.DefaultBeanNameGenerator 调用工具类方法进行生成 1 2 3 4 @Override public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { return BeanDefinitionReaderUtils.generateBeanName(definition, registry); } ClassName + # + 十六进制字符 parentName + $child + # + 十</description>
    </item>
    <item>
      <title>Spring-BeanFactoryPostProcessor</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanFactoryPostProcessor/</link>
      <pubDate>Wed, 06 Mar 2024 12:53:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanFactoryPostProcessor/</guid>
      <description>Spring BeanFactoryPostProcessor Author: HuiFer 源码阅读仓库: SourceHot-Spring 作用: 定制或修改BeanDefinition的属性 Demo 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 public class ChangeAttrBeanPostProcessor implements BeanFactoryPostProcessor { private Set&amp;lt;String&amp;gt; attr; public ChangeAttrBeanPostProcessor() { attr = new HashSet&amp;lt;&amp;gt;(); } public Set&amp;lt;String&amp;gt; getAttr() { return attr; } public void setAttr(Set&amp;lt;String&amp;gt; attr) { this.attr = attr; } @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames(); for (String beanName : beanDefinitionNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); StringValueResolver stringValueResolver = new StringValueResolver() { @Override public String resolveStringValue(String</description>
    </item>
    <item>
      <title>Spring-BeanDefinitionReaderUtils</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanDefinitionReaderUtils/</link>
      <pubDate>Wed, 06 Mar 2024 12:52:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanDefinitionReaderUtils/</guid>
      <description>Spring BeanDefinitionReaderUtils Author: HuiFer 源码阅读仓库: SourceHot-spring createBeanDefinition org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 public static AbstractBeanDefinition createBeanDefinition( @Nullable String parentName, @Nullable String className, @Nullable ClassLoader classLoader) throws ClassNotFoundException { GenericBeanDefinition bd = new GenericBeanDefinition(); // 设置 父bean bd.setParentName(parentName); if (className != null) { if (classLoader != null) { // 设置 class // 内部是通过反射创建 class bd.setBeanClass(ClassUtils.forName(className, classLoader)); } else { // 设置 class name bd.setBeanClassName(className); } } return bd; } generateBeanName org.springframework.beans.factory.support.BeanDefinitionReaderUtils.generateBeanName(org.springframework.beans.factory.config.BeanDefinition, org.springframework.beans.factory.support.BeanDefinitionRegistry, boolean) 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</description>
    </item>
    <item>
      <title>Spring-BeanDefinitionParserDelegate</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanDefinitionParserDelegate/</link>
      <pubDate>Wed, 06 Mar 2024 12:51:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-BeanDefinitionParserDelegate/</guid>
      <description>Spring BeanDefinitionParserDelegate Author: HuiFer 源码阅读仓库: SourceHot-spring 全路径org.springframework.beans.factory.xml.BeanDefinitionParserDelegate 解析 xml 中标签的委托类 在这个类中定义常量如下，为后续解析提供帮助 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</description>
    </item>
    <item>
      <title>Spring-ApplicationListener</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-ApplicationListener/</link>
      <pubDate>Wed, 06 Mar 2024 12:50:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-ApplicationListener/</guid>
      <description>Spring initApplicationEventMulticaster Author: HuiFer 源码阅读仓库: SourceHot-Spring demo 1 2 3 4 5 6 7 8 9 10 11 package com.huifer.source.spring.applicationListener; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; public class DemoApplicationListener implements ApplicationListener { @Override public void onApplicationEvent(ApplicationEvent event) { System.out.println(&amp;#34;com.huifer.source.spring.applicationListener.DemoApplicationListener.onApplicationEvent&amp;#34;); } } 1 2 3 4 5 6 7 &amp;lt;?xml version=&amp;#34;1.0&amp;#34; encoding=&amp;#34;UTF-8&amp;#34;?&amp;gt; &amp;lt;beans xmlns:xsi=&amp;#34;http://www.w3.org/2001/XMLSchema-instance&amp;#34; xmlns=&amp;#34;http://www.springframework.org/schema/beans&amp;#34; xsi:schemaLocation=&amp;#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&amp;#34;&amp;gt; &amp;lt;bean id=&amp;#34;demoApplicationListener&amp;#34; class=&amp;#34;com.huifer.source.spring.applicationListener.DemoApplicationListener&amp;#34;/&amp;gt; &amp;lt;/beans&amp;gt; 1 2 3 4 5 public class ListenerSourceCode { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(&amp;#34;Listener-demo.xml&amp;#34;); } } 初始化入口 org.springframework.context.support.AbstractAppli</description>
    </item>
    <item>
      <title>Spring-AnnotationUtils</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-AnnotationUtils/</link>
      <pubDate>Wed, 06 Mar 2024 12:49:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/Spring-AnnotationUtils/</guid>
      <description>Spring AnnotationUtils Author: HuiFer 源码阅读仓库: SourceHot-Spring org.springframework.core.annotation.AnnotationUtils提供了注解相关的方法 getAnnotation: 获取注解 findAnnotation: 寻找注解 getValue: 获取属性值 getDefaultValue: 获取默认值 getAnnotation 测试用例如下 1 2 3 4 5 6 7 @Test public void findMethodAnnotationOnLeaf() throws Exception { Method m = Leaf.class.getMethod(&amp;#34;annotatedOnLeaf&amp;#34;); assertNotNull(m.getAnnotation(Order.class)); assertNotNull(getAnnotation(m, Order.class)); assertNotNull(findAnnotation(m, Order.class)); } org.springframework.core.annotation.AnnotationUtils.getAnnotation(java.lang.reflect.Method, java.lang.Class&amp;lt;A&amp;gt;) 1 2 3 4 5 6 7 8 9 10 11 12</description>
    </item>
    <item>
      <title>Spring-StubPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-StubPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:48:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-StubPropertySource/</guid>
      <description>Spring StubPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 整体代码如下. 通过 StubPropertySource 的 getProperty 方法永远返回 null 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public static class StubPropertySource extends PropertySource&amp;lt;Object&amp;gt; { public StubPropertySource(String name) { super(name, new Object()); } /** * Always returns {@code null}. */ @Override @Nullable public String getProperty(String name) { return null; } }</description>
    </item>
    <item>
      <title>Spring-SimpleCommandLinePropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-SimpleCommandLinePropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:47:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-SimpleCommandLinePropertySource/</guid>
      <description>Spring SimpleCommandLinePropertySource 全路径: org.springframework.core.env.SimpleCommandLinePropertySource 1 public class SimpleCommandLinePropertySource extends CommandLinePropertySource&amp;lt;CommandLineArgs&amp;gt; {} SimpleCommandLinePropertySource 的 source 类型是 CommandLineArgs 具体解释请看下面分析 CommandLineArgs 两个内部属性 1 2 3 4 5 6 7 8 9 10 11 12 class CommandLineArgs { /** * 选项参数列表 */ private final Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; optionArgs = new HashMap&amp;lt;&amp;gt;(); /** * 非选项参数列表 */ private final List&amp;lt;String&amp;gt; nonOptionArgs = new ArrayList&amp;lt;&amp;gt;(); } addOptionArg 添加 选项参数 1 2 3 4 5 6 7 8 public void addOptionArg(String optionName, @Nullable String optionValue) { if (!this.optionArgs.containsKey(optionName)) { this.optionArgs.put(optionName, new ArrayList&amp;lt;&amp;gt;()); } if (optionValue != null) { this.optionArgs.get(optionName).add(optionValue); } } getOptionNames 获取选项参数列表 1 2 3 public Set&amp;lt;String&amp;gt;</description>
    </item>
    <item>
      <title>Spring-SimpleCommandLineArgsParser</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-SimpleCommandLineArgsParser/</link>
      <pubDate>Wed, 06 Mar 2024 12:46:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-SimpleCommandLineArgsParser/</guid>
      <description>Spring SimpleCommandLineArgsParser Author: HuiFer 源码阅读仓库: SourceHot-spring 类全路径: `org.springframework.core.env.SimpleCommandLineArgsParser 类作用: 将命令行参数解析成 org.springframework.core.env.CommandLineArgs 完整代码如下. 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 class SimpleCommandLineArgsParser { /** * Parse the given {@code String} array based on the rules described {@linkplain * SimpleCommandLineArgsParser above}, returning a fully-populated * {@link CommandLineArgs} object. * @param args command line arguments, typically from a {@code main()} method */ public CommandLineArgs parse(String... args) { CommandLineArgs commandLineArgs = new CommandLineArgs(); for (String arg : args) { if (arg.startsWith(&amp;#34;--&amp;#34;)) { String optionText = arg.substring(2, arg.length()); String</description>
    </item>
    <item>
      <title>Spring-ServletContextPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ServletContextPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:45:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ServletContextPropertySource/</guid>
      <description>Spring ServletContextPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 类全路径: org.springframework.web.context.support.ServletContextPropertySource 内部数据结构是 ServletContext 接口 整体代码如下. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class ServletContextPropertySource extends EnumerablePropertySource&amp;lt;ServletContext&amp;gt; { public ServletContextPropertySource(String name, ServletContext servletContext) { super(name, servletContext); } @Override public String[] getPropertyNames() { // javax.servlet.ServletContext.getInitParameterNames 方法调用 return StringUtils.toStringArray(this.source.getInitParameterNames()); } @Override @Nullable public String getProperty(String name) { // javax.servlet.ServletContext.getInitParameter return this.source.getInitParameter(name); } }</description>
    </item>
    <item>
      <title>Spring-ServletConfigPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ServletConfigPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:44:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ServletConfigPropertySource/</guid>
      <description>Spring ServletConfigPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 类全路径: org.springframework.web.context.support.ServletConfigPropertySource 内部数据结构是 ServletConfig 整体代码如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class ServletConfigPropertySource extends EnumerablePropertySource&amp;lt;ServletConfig&amp;gt; { public ServletConfigPropertySource(String name, ServletConfig servletConfig) { super(name, servletConfig); } @Override public String[] getPropertyNames() { // javax.servlet.ServletConfig.getInitParameterNames return StringUtils.toStringArray(this.source.getInitParameterNames()); } @Override @Nullable public String getProperty(String name) { // javax.servlet.ServletConfig.getInitParameter return this.source.getInitParameter(name); } }</description>
    </item>
    <item>
      <title>Spring-ResourcePropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ResourcePropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:43:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ResourcePropertySource/</guid>
      <description>Spring ResourcePropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 全路径: org.springframework.core.io.support.ResourcePropertySource source 依然是 map 结构 getNameForResource 1 2 3 4 5 6 7 8 9 private static String getNameForResource(Resource resource) { // 获取 resource 的介绍 String name = resource.getDescription(); if (!StringUtils.hasText(name)) { // 短类名+@+hashcode name = resource.getClass().getSimpleName() + &amp;#34;@&amp;#34; + System.identityHashCode(resource); } return name; } withName 创建 ResourcePropertySource 对象, 根据 name 属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public ResourcePropertySource withName(String name) { if (this.name.equals(name)) { return this; } // Store the original resource name if necessary... if (this.resourceName != null) { if (this.resourceName.equals(name)) { return new ResourcePropertySource(this.resourceName,</description>
    </item>
    <item>
      <title>Spring-PropertiesPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-PropertiesPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:42:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-PropertiesPropertySource/</guid>
      <description>Spring PropertiesPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 全路径: org.springframework.core.env.PropertiesPropertySource Properties 是 map 结构。可以做类型转换. getPropertyNames 就转换成了父类 MapPropertySource 的方法了 map.keySet() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public class PropertiesPropertySource extends MapPropertySource { @SuppressWarnings({&amp;#34;rawtypes&amp;#34;, &amp;#34;unchecked&amp;#34;}) public PropertiesPropertySource(String name, Properties source) { super(name, (Map) source); } protected PropertiesPropertySource(String name, Map&amp;lt;String, Object&amp;gt; source) { super(name, source); } @Override public String[] getPropertyNames() { synchronized (this.source) { return super.getPropertyNames(); } } }</description>
    </item>
    <item>
      <title>Spring-MockPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-MockPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:41:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-MockPropertySource/</guid>
      <description>Spring MockPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 内部 source 是 Properties 类型 withProperty 设置属性名称和属性值 1 2 3 4 public MockPropertySource withProperty(String name, Object value) { this.setProperty(name, value); return this; } setProperty 1 2 3 public void setProperty(String name, Object value) { this.source.put(name, value); } 完整代码 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 public class MockPropertySource extends PropertiesPropertySource { /** * {@value} is</description>
    </item>
    <item>
      <title>Spring-MapPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-MapPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:40:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-MapPropertySource/</guid>
      <description>Spring MapPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 类全路径: org.springframework.core.env.MapPropertySource 内部数据结构是一个Map&amp;lt;String,Object&amp;gt; 这是一个对 map 的操作. 整体代码如下. 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 public class MapPropertySource extends EnumerablePropertySource&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt; { public MapPropertySource(String name, Map&amp;lt;String, Object&amp;gt; source) { super(name, source); } @Override @Nullable public Object getProperty(String name) { // 从map中获取 name 对应的value return this.source.get(name); }</description>
    </item>
    <item>
      <title>Spring-EnumerablePropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-EnumerablePropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:39:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-EnumerablePropertySource/</guid>
      <description>Spring EnumerablePropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 全路径: org.springframework.core.env.EnumerablePropertySource 在这个类中定义了一个抽象方法getPropertyNames 用来获取所有的 property 的名称 1 public abstract String[] getPropertyNames(); 整体代码如下 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 public abstract class EnumerablePropertySource&amp;lt;T&amp;gt; extends PropertySource&amp;lt;T&amp;gt; { public EnumerablePropertySource(String name, T source) { super(name, source); } protected EnumerablePropertySource(String name) { super(name); } /** * Return whether this {@code PropertySource} contains a property with the given name. * &amp;lt;p&amp;gt;This implementation</description>
    </item>
    <item>
      <title>Spring-CompositePropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-CompositePropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:38:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-CompositePropertySource/</guid>
      <description>Spring CompositePropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 全路径: org.springframework.core.env.CompositePropertySource 整体代码如下 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 public class CompositePropertySource extends EnumerablePropertySource&amp;lt;Object&amp;gt; { /** * set 集合 */ private final Set&amp;lt;PropertySource&amp;lt;?&amp;gt;&amp;gt; propertySources = new LinkedHashSet&amp;lt;&amp;gt;(); /** * Create</description>
    </item>
    <item>
      <title>Spring-ComparisonPropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ComparisonPropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:37:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-ComparisonPropertySource/</guid>
      <description>Spring ComparisonPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 整体代码如下. 下面几个调用方法会直接抛出异常 getSource containsProperty getProperty 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 static class ComparisonPropertySource extends StubPropertySource { // 异常信息 private static final String USAGE_ERROR = &amp;#34;ComparisonPropertySource instances are for use with collection comparison only&amp;#34;; public ComparisonPropertySource(String name) { super(name); } @Override public Object getSource() { // 抛异常 throw new UnsupportedOperationException(USAGE_ERROR); } @Override public boolean containsProperty(String name) { // 抛异常 throw new UnsupportedOperationException(USAGE_ERROR); } @Override @Nullable public String getProperty(String name) { // 抛异常 throw new UnsupportedOperationException(USAGE_ERROR); }</description>
    </item>
    <item>
      <title>Spring-CommandLinePropertySource</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-CommandLinePropertySource/</link>
      <pubDate>Wed, 06 Mar 2024 12:36:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PropertySource/Spring-CommandLinePropertySource/</guid>
      <description>Spring CommandLinePropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 类全路径: org.springframework.core.env.CommandLinePropertySource 作用: 用来存储命令行参数 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 69 70 71 72 73 74 75 76 77 78 79 public abstract class CommandLinePropertySource&amp;lt;T&amp;gt; extends EnumerablePropertySource&amp;lt;T&amp;gt; { public static final String COMMAND_LINE_PROPERTY_SOURCE_NAME = &amp;#34;commandLineArgs&amp;#34;; public static final String DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME = &amp;#34;nonOptionArgs&amp;#34;; private String nonOptionArgsPropertyName = DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME; public CommandLinePropertySource(T source) { //</description>
    </item>
    <item>
      <title>Spring-SystemPropertyPlaceholderResolver</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-SystemPropertyPlaceholderResolver/</link>
      <pubDate>Wed, 06 Mar 2024 12:35:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-SystemPropertyPlaceholderResolver/</guid>
      <description>Spring SystemPropertyPlaceholderResolver 类全路径: org.springframework.util.SystemPropertyUtils.SystemPropertyPlaceholderResolver 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 private static class SystemPropertyPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver { private final String text; public SystemPropertyPlaceholderResolver(String text) { this.text = text; } @Override @Nullable public String resolvePlaceholder(String placeholderName) { try { String propVal = System.getProperty(placeholderName); if (propVal == null) { // Fall back to searching the system environment. // 获取系统属性 propVal = System.getenv(placeholderName); } return propVal; } catch (Throwable ex) { System.err.println(&amp;#34;Could not resolve placeholder &amp;#39;&amp;#34; + placeholderName + &amp;#34;&amp;#39; in [&amp;#34; + this.text + &amp;#34;] as system property: &amp;#34; + ex); return null; } } }</description>
    </item>
    <item>
      <title>Spring-ServletContextPlaceholderResolver</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-ServletContextPlaceholderResolver/</link>
      <pubDate>Wed, 06 Mar 2024 12:34:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-ServletContextPlaceholderResolver/</guid>
      <description>Spring ServletContextPlaceholderResolver 类全路径: org.springframework.web.util.ServletContextPropertyUtils.ServletContextPlaceholderResolver 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 private static class ServletContextPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver { private final String text; private final ServletContext servletContext; public ServletContextPlaceholderResolver(String text, ServletContext servletContext) { this.text = text; this.servletContext = servletContext; } @Override @Nullable public String resolvePlaceholder(String placeholderName) { try { // servlet 上下文获取 String propVal = this.servletContext.getInitParameter(placeholderName); if (propVal == null) { // Fall back to system properties. propVal = System.getProperty(placeholderName); if (propVal == null) { // Fall back to searching the system environment. propVal = System.getenv(placeholderName); } } return propVal; } catch (Throwable ex) { System.err.println(&amp;#34;Could not resolve placeholder &amp;#39;&amp;#34; + placeholderName + &amp;#34;&amp;#39; in</description>
    </item>
    <item>
      <title>Spring-PropertyPlaceholderConfigurerResolver</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-PropertyPlaceholderConfigurerResolver/</link>
      <pubDate>Wed, 06 Mar 2024 12:33:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-PropertyPlaceholderConfigurerResolver/</guid>
      <description>Spring PropertyPlaceholderConfigurerResolver 类全路径: org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.PropertyPlaceholderConfigurerResolver 这个类是从 Properties 中获取属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 private final class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver { private final Properties props; private PropertyPlaceholderConfigurerResolver(Properties props) { this.props = props; } @Override @Nullable public String resolvePlaceholder(String placeholderName) { return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName, this.props, systemPropertiesMode); } } 详细方法如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @Nullable protected String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) { String propVal = null; if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) { propVal = resolveSystemProperty(placeholder); } if (propVal == null) { propVal = resolvePlaceholder(placeholder, props); } if (propVal == null &amp;amp;&amp;amp; systemPropertiesMode == SYSTEM_PROPERTIES_MODE_FALLBACK) { propVal = resolveSystemProperty(placeholder); } return propVal; } 1 2 3 4</description>
    </item>
    <item>
      <title>Spring-PlaceholderResolver</title>
      <link>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-PlaceholderResolver/</link>
      <pubDate>Wed, 06 Mar 2024 12:32:00 +0000</pubDate>
      <guid>https://index.zshipu.com/geek/post/code/docs/Spring/clazz/PlaceholderResolver/Spring-PlaceholderResolver/</guid>
      <description>Spring PlaceholderResolver 类全路径: org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver 类作用将占位符中的内容替换成属性值. 假设现有属性表: user.dir = c:\home 传入参数 user.dir 会获得 c:\home 1 2 3 4 5 6 7 8 9 10 11 12 @FunctionalInterface public interface PlaceholderResolver { /** * Resolve the supplied placeholder name to the replacement value. * @param placeholderName the name of the placeholder to resolve * @return the replacement value, or {@code null} if no replacement is to be made */ @Nullable String resolvePlaceholder(String placeholderName); } 类图如下</description>
    </item>
  </channel>
</rss>
