2024年3月6日
Spring MessageConverter Author: HuiFer 源码阅读仓库: SourceHot-spring 源码路径: org.springframework.messaging.converter.MessageConverter MessageConverter 消息转换接口 类图如下 两个方法 fromMessage: 从消息转换到 Object 1 Object fromMessage(Message<?> message, Class<?> targetClass); toMessage: 从 Object 转换到消息 1 Message<?> toMessage(Object payload, @Nullable MessageHeaders headers); 序号 class 作用 1 ByteArrayMessageConverter byte 数组消息转换器 2 MappingJackson2MessageConverter jackson2 的消息转换器 3 MarshallingMessageConverter xml 的消息转换器 4 StringMessageConverter 字符串消息转换器 AbstractMessageConverter 类图: fromMessage 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 @Override @Nullable public final Object fromMessage(Message<?> message,……
阅读全文
2024年3月6日
Spring JmsTemplate Author: HuiFer 源码阅读仓库: SourceHot-spring 源码路径: org.springframework.jms.core.JmsTemplate 源码分析 send 发送消息 1 2 3 4 5 6 7 8 9 @Override public void send(final String destinationName, final MessageCreator messageCreator) throws JmsException { // 执行. execute(session -> { Destination destination = resolveDestinationName(session, destinationName); doSend(session, destination, messageCreator); return null; }, false); } 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 @Nullable public <T> T execute(SessionCallback<T> action, boolean startConnection) throws JmsException { Assert.notNull(action, "Callback object must not be null"); Connection conToClose = null; Session sessionToClose = null; try { Session sessionToUse = ConnectionFactoryUtils.doGetTransactionalSession( obtainConnectionFactory(), this.transactionalResourceFactory, startConnection); if (sessionToUse ==……
阅读全文
2024年3月6日
Spring EnableJms 注解 Author: HuiFer 源码阅读仓库: SourceHot-spring 源码路径: org.springframework.jms.annotation.EnableJms 源码分析 1 2 3 4 5 6 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Import(JmsBootstrapConfiguration.class) public @interface EnableJms { } 该类的切入点在@Import(JmsBootstrapConfiguration.class) , 直接看JmsBootstrapConfiguration就可以了 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21……
阅读全文
2024年3月6日
Spring Printer 类全路径: org.springframework.format.Printer 类作用: 对象转换成字符串 1 2 3 4 5 6 7 8 9 10 11 12 13 @FunctionalInterface public interface Printer<T> { /** * 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); }……
阅读全文
2024年3月6日
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<T> { /** * 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; } 类图……
阅读全文
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()); // 判断时间格式是……
阅读全文