Skip to content

Commit 4ec3e10

Browse files
committed
Add runtime hints for WebFlux
Closes gh-28701
1 parent b312eca commit 4ec3e10

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.http.codec;
18+
19+
import org.springframework.aot.hint.MemberCategory;
20+
import org.springframework.aot.hint.RuntimeHints;
21+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
22+
import org.springframework.aot.hint.TypeReference;
23+
import org.springframework.http.codec.support.DefaultClientCodecConfigurer;
24+
import org.springframework.http.codec.support.DefaultServerCodecConfigurer;
25+
import org.springframework.lang.Nullable;
26+
27+
/**
28+
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
29+
* implementations listed in {@code CodecConfigurer.properties}.
30+
*
31+
* @author Sebastien Deleuze
32+
* @since 6.0
33+
*/
34+
public class CodecConfigurerHintsRegistrar implements RuntimeHintsRegistrar {
35+
36+
@Override
37+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
38+
hints.resources().registerPattern("org/springframework/http/codec/CodecConfigurer.properties");
39+
hints.reflection().registerType(DefaultClientCodecConfigurer.class, builder ->
40+
builder.onReachableType(TypeReference.of(CodecConfigurerFactory.class))
41+
.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
42+
hints.reflection().registerType(DefaultServerCodecConfigurer.class, builder ->
43+
builder.onReachableType(TypeReference.of(CodecConfigurerFactory.class))
44+
.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
45+
}
46+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar= \
2-
org.springframework.http.MediaTypeResourceHintsRegistrar
2+
org.springframework.http.MediaTypeResourceHintsRegistrar,\
3+
org.springframework.http.codec.CodecConfigurerHintsRegistrar

spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.ApplicationContext;
2929
import org.springframework.context.ApplicationContextAware;
3030
import org.springframework.context.annotation.Bean;
31+
import org.springframework.context.annotation.ImportRuntimeHints;
3132
import org.springframework.core.ReactiveAdapterRegistry;
3233
import org.springframework.core.annotation.Order;
3334
import org.springframework.core.convert.converter.Converter;
@@ -45,6 +46,7 @@
4546
import org.springframework.validation.MessageCodesResolver;
4647
import org.springframework.validation.Validator;
4748
import org.springframework.web.bind.WebDataBinder;
49+
import org.springframework.web.bind.annotation.WebAnnotationsRuntimeHintsRegistrar;
4850
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
4951
import org.springframework.web.cors.CorsConfiguration;
5052
import org.springframework.web.reactive.DispatcherHandler;
@@ -83,6 +85,7 @@
8385
* @author Brian Clozel
8486
* @since 5.0
8587
*/
88+
@ImportRuntimeHints(WebAnnotationsRuntimeHintsRegistrar.class)
8689
public class WebFluxConfigurationSupport implements ApplicationContextAware {
8790

8891
@Nullable

0 commit comments

Comments
 (0)