diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java index 179ae215528..45bc4d0f1a1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,9 +67,12 @@ public class ProtobufMessageConverter extends AbstractMessageConverter { */ public static final MimeType PROTOBUF = new MimeType("application", "x-protobuf", DEFAULT_CHARSET); + private static final boolean protobufJsonFormatPresent = + ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", ProtobufMessageConverter.class.getClassLoader()); private static final Map, Method> methodCache = new ConcurrentReferenceHashMap<>(); + final ExtensionRegistry extensionRegistry; @Nullable @@ -98,7 +101,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter { if (formatSupport != null) { this.protobufFormatSupport = formatSupport; } - else if (ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", getClass().getClassLoader())) { + else if (protobufJsonFormatPresent) { this.protobufFormatSupport = new ProtobufJavaUtilSupport(null, null); } else { diff --git a/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java index ec4ad27ee00..1c20e75774b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,9 +105,19 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter, Method> methodCache = new ConcurrentReferenceHashMap<>(); + static { + ClassLoader classLoader = ProtobufHttpMessageConverter.class.getClassLoader(); + protobufFormatFactoryPresent = ClassUtils.isPresent("com.googlecode.protobuf.format.FormatFactory", classLoader); + protobufJsonFormatPresent = ClassUtils.isPresent("com.google.protobuf.util.JsonFormat", classLoader); + } + + final ExtensionRegistry extensionRegistry; @Nullable @@ -136,10 +146,10 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter corsConfigurations; @@ -384,7 +388,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { public Validator webFluxValidator() { Validator validator = getValidator(); if (validator == null) { - if (ClassUtils.isPresent("jakarta.validation.Validator", getClass().getClassLoader())) { + if (jakartaValidatorPresent) { try { validator = new OptionalValidatorFactoryBean(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceHandler.java index f19ad1532da..2cc8c159aac 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.util.ClassUtils; */ public class WebSocketNamespaceHandler extends NamespaceHandlerSupport { - private static boolean isSpringMessagingPresent = ClassUtils.isPresent( + private static final boolean isSpringMessagingPresent = ClassUtils.isPresent( "org.springframework.messaging.Message", WebSocketNamespaceHandler.class.getClassLoader());