2024年3月6日
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("--")) { String optionText = arg.substring(2, arg.length()); String……
阅读全文
2024年3月6日
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<ServletContext> { 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); } }……
阅读全文
2024年3月6日
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<ServletConfig> { 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); } }……
阅读全文
2024年3月6日
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() + "@" + 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,……
阅读全文
2024年3月6日
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({"rawtypes", "unchecked"}) public PropertiesPropertySource(String name, Properties source) { super(name, (Map) source); } protected PropertiesPropertySource(String name, Map<String, Object> source) { super(name, source); } @Override public String[] getPropertyNames() { synchronized (this.source) { return super.getPropertyNames(); } } }……
阅读全文
2024年3月6日
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……
阅读全文
2024年3月6日
Spring MapPropertySource Author: HuiFer 源码阅读仓库: SourceHot-spring 类全路径: org.springframework.core.env.MapPropertySource 内部数据结构是一个Map<String,Object> 这是一个对 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<Map<String, Object>> { public MapPropertySource(String name, Map<String, Object> source) { super(name, source); } @Override @Nullable public Object getProperty(String name) { // 从map中获取 name 对应的value return this.source.get(name); }……
阅读全文
2024年3月6日
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<T> extends PropertySource<T> { 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. * <p>This implementation……
阅读全文
2024年3月6日
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<Object> { /** * set 集合 */ private final Set<PropertySource<?>> propertySources = new LinkedHashSet<>(); /** * Create……
阅读全文
2024年3月6日
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 = "ComparisonPropertySource instances are for use with collection comparison only"; 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); }……
阅读全文
-
上一页
-
1
-
...
-
39
-
40
-
41
-
42
-
43
-
...
-
250
-
下一页