<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>PropertySource on 知识铺的博客</title>
    <link>https://index.zshipu.com/geek/tags/PropertySource/</link>
    <description>Recent content in PropertySource on 知识铺的博客</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-CN</language>
    <lastBuildDate>Wed, 06 Mar 2024 12:48:00 +0000</lastBuildDate>
    <atom:link href="https://index.zshipu.com/geek/tags/PropertySource/index.xml" rel="self" type="application/rss+xml" />
    <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>
  </channel>
</rss>
