2024年3月6日
Spring Formatter 类全路径: org.springframework.format.Formatter 1 2 3 public interface Formatter<T> extends Printer<T>, Parser<T> { } 该接口继承了 printer 和 parser 两个接口. 比较常见的有: DateFormatter 就是继承这个接口.……
阅读全文
2024年3月6日
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<A extends Annotation> { /** * The types of fields that may be annotated with the <A> annotation. * 字段类型 */ Set<Class<?>> getFieldTypes(); /** * Get the Printer to print the value of a field of {@code fieldType} annotated with * {@code annotation}. * <p>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……
阅读全文
2024年3月6日
Spring MillisecondInstantPrinter 类全路径: org.springframework.format.datetime.joda.MillisecondInstantPrinter 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public final class MillisecondInstantPrinter implements Printer<Long> { private final DateTimeFormatter formatter; /** * Create a new ReadableInstantPrinter. * @param formatter the Joda DateTimeFormatter instance */ public MillisecondInstantPrinter(DateTimeFormatter formatter) { this.formatter = formatter; } @Override public String print(Long instant, Locale locale) { // DateTimeFormatter .print return JodaTimeContextHolder.getFormatter(this.formatter, locale).print(instant); } }……
阅读全文
2024年3月6日
Spring DateTimeParser 类全路径: org.springframework.format.datetime.joda.DateTimeParser 代码如下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public final class DateTimeParser implements Parser<DateTime> { private final DateTimeFormatter formatter; /** * Create a new DateTimeParser. * @param formatter the Joda DateTimeFormatter instance */ public DateTimeParser(DateTimeFormatter formatter) { this.formatter = formatter; } @Override public DateTime parse(String text, Locale locale) throws ParseException { // DateTimeFormatter 转换字符串事件类型 return JodaTimeContextHolder.getFormatter(this.formatter, locale).parseDateTime(text); } }……
阅读全文
2024年3月6日
Spring DateTimeFormatAnnotationFormatterFactory 类全路径: org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory 类图 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 public class DateTimeFormatAnnotationFormatterFactory extends EmbeddedValueResolutionSupport implements AnnotationFormatterFactory<DateTimeFormat> { /** * 字段类型 */ private static final Set<Class<?>> FIELD_TYPES; @Override public Set<Class<?>> getFieldTypes() { return FIELD_TYPES; } @Override public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) { return getFormatter(annotation, fieldType); } @Override public Parser<?> getParser(DateTimeFormat annotation, Class<?> fieldType) { return getFormatter(annotation, fieldType); } protected Formatter<Date> getFormatter(DateTimeFormat annotation, Class<?> fieldType) { DateFormatter formatter = new DateFormatter(); // style String style = resolveEmbeddedValue(annotation.style()); // 判断时间格式是……
阅读全文
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……
阅读全文