2024年3月6日
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……
阅读全文
2024年3月6日
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 && !p2) { return -1; } else if (p2 && !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 && sourceProvider……
阅读全文
2024年3月6日
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<K, V> extends Map<K, List<V>> { /** * 获取value的第一 */ @Nullable V getFirst(K key); /** * 添加元素 */ void add(K key, @Nullable V value); /** * 添加所有元素 */ void addAll(K key, List<? extends V> values); /** * 添加要给 {@link MultiValueMap} 对象 */ void addAll(MultiValueMap<K, V> values); default void addIfAbsent(K key, @Nullable V value) {……
阅读全文
2024年3月6日
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 中……
阅读全文
2024年3月6日
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(); /** * 是否允许创……
阅读全文
2024年3月6日
Spring MessageSource Author: HuiFer 源码阅读仓库: SourceHot-Spring 初始化入口 org.springframework.context.support.AbstractApplicationContext.refresh方法有initMessageSource()方法进行了MessageSource初始化 1 2 3 4 5 6 7 8 9 10……
阅读全文
2024年3月6日
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<?>[] 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. * <p>Note that {@link BeanDefinitionRegistryPostProcessor} types may <em>not</em> be * registered here, due to lifecycle constraints related to {@code @Configuration} * class processing. * * 对impor……
阅读全文
2024年3月6日
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's default behavior. return null; } 上述这段代码是针对 xml 进行校验 1 2 3 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 如上所示以.x……
阅读全文
2024年3月6日
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("tb", tb); assertSame(tb, beanRegistry.getSingleton("tb")); TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", new ObjectFactory<Object>() { @Override public Object getObject() throws BeansException { return new TestBean(); } }); assertSame(tb2, beanRegistry.getSingleton("tb2")); assertSame(tb, beanRegistry.getSingleton("tb")); assertSame(tb2, beanRegistry.getSingleton("tb2")); assertEquals(2, beanRegistry.getSingletonCount()); String[] names = beanRegistry.getSingletonNames();……
阅读全文
2024年3月6日
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 <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.w3.org/2001/XMLSchema"……
阅读全文
-
上一页
-
1
-
...
-
37
-
38
-
39
-
40
-
41
-
...
-
250
-
下一页