Skip to content

Commit e2f8fcf

Browse files
committed
Merge branch '3.0.x' into 3.1.x
Closes gh-36121
2 parents 20321b5 + 6effd60 commit e2f8fcf

File tree

9 files changed

+79
-77
lines changed

9 files changed

+79
-77
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@
2929
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3030
import org.springframework.context.ApplicationContext;
3131
import org.springframework.context.annotation.Import;
32-
import org.springframework.context.annotation.ImportRuntimeHints;
3332
import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory;
3433

3534
/**
@@ -45,7 +44,6 @@
4544
@EnableConfigurationProperties(FreeMarkerProperties.class)
4645
@Import({ FreeMarkerServletWebConfiguration.class, FreeMarkerReactiveWebConfiguration.class,
4746
FreeMarkerNonWebConfiguration.class })
48-
@ImportRuntimeHints(FreeMarkerRuntimeHints.class)
4947
public class FreeMarkerAutoConfiguration {
5048

5149
private static final Log logger = LogFactory.getLog(FreeMarkerAutoConfiguration.class);

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerRuntimeHints.java

-34
This file was deleted.

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProvider.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,11 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.springframework.aot.hint.RuntimeHints;
2324
import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider;
2425
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
26+
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar;
27+
import org.springframework.util.ClassUtils;
2528

2629
/**
2730
* {@link TemplateAvailabilityProvider} that provides availability information for
@@ -32,8 +35,10 @@
3235
*/
3336
public class FreeMarkerTemplateAvailabilityProvider extends PathBasedTemplateAvailabilityProvider {
3437

38+
private static final String REQUIRED_CLASS_NAME = "freemarker.template.Configuration";
39+
3540
public FreeMarkerTemplateAvailabilityProvider() {
36-
super("freemarker.template.Configuration", FreeMarkerTemplateAvailabilityProperties.class, "spring.freemarker");
41+
super(REQUIRED_CLASS_NAME, FreeMarkerTemplateAvailabilityProperties.class, "spring.freemarker");
3742
}
3843

3944
protected static final class FreeMarkerTemplateAvailabilityProperties extends TemplateAvailabilityProperties {
@@ -60,4 +65,19 @@ public void setTemplateLoaderPath(List<String> templateLoaderPath) {
6065

6166
}
6267

68+
static class FreeMarkerTemplateAvailabilityRuntimeHints extends BindableRuntimeHintsRegistrar {
69+
70+
FreeMarkerTemplateAvailabilityRuntimeHints() {
71+
super(FreeMarkerTemplateAvailabilityProperties.class);
72+
}
73+
74+
@Override
75+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
76+
if (ClassUtils.isPresent(REQUIRED_CLASS_NAME, classLoader)) {
77+
super.registerHints(hints, classLoader);
78+
}
79+
}
80+
81+
}
82+
6383
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.context.ApplicationContext;
3939
import org.springframework.context.annotation.Bean;
4040
import org.springframework.context.annotation.Configuration;
41-
import org.springframework.context.annotation.ImportRuntimeHints;
4241
import org.springframework.context.i18n.LocaleContextHolder;
4342
import org.springframework.core.log.LogMessage;
4443
import org.springframework.web.servlet.view.UrlBasedViewResolver;
@@ -60,7 +59,6 @@
6059
@AutoConfiguration(after = WebMvcAutoConfiguration.class)
6160
@ConditionalOnClass(MarkupTemplateEngine.class)
6261
@EnableConfigurationProperties(GroovyTemplateProperties.class)
63-
@ImportRuntimeHints(GroovyTemplateRuntimeHints.class)
6462
public class GroovyTemplateAutoConfiguration {
6563

6664
private static final Log logger = LogFactory.getLog(GroovyTemplateAutoConfiguration.class);

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProvider.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,11 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.springframework.aot.hint.RuntimeHints;
2324
import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider;
2425
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
26+
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar;
27+
import org.springframework.util.ClassUtils;
2528

2629
/**
2730
* {@link TemplateAvailabilityProvider} that provides availability information for Groovy
@@ -32,8 +35,10 @@
3235
*/
3336
public class GroovyTemplateAvailabilityProvider extends PathBasedTemplateAvailabilityProvider {
3437

38+
private static final String REQUIRED_CLASS_NAME = "groovy.text.TemplateEngine";
39+
3540
public GroovyTemplateAvailabilityProvider() {
36-
super("groovy.text.TemplateEngine", GroovyTemplateAvailabilityProperties.class, "spring.groovy.template");
41+
super(REQUIRED_CLASS_NAME, GroovyTemplateAvailabilityProperties.class, "spring.groovy.template");
3742
}
3843

3944
protected static final class GroovyTemplateAvailabilityProperties extends TemplateAvailabilityProperties {
@@ -60,4 +65,19 @@ public void setResourceLoaderPath(List<String> resourceLoaderPath) {
6065

6166
}
6267

68+
static class GroovyTemplateAvailabilityRuntimeHints extends BindableRuntimeHintsRegistrar {
69+
70+
GroovyTemplateAvailabilityRuntimeHints() {
71+
super(GroovyTemplateAvailabilityProperties.class);
72+
}
73+
74+
@Override
75+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
76+
if (ClassUtils.isPresent(REQUIRED_CLASS_NAME, classLoader)) {
77+
super.registerHints(hints, classLoader);
78+
}
79+
}
80+
81+
}
82+
6383
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateRuntimeHints.java

-34
This file was deleted.

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/aot.factories

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=\
2+
org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityRuntimeHints,\
3+
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityRuntimeHints,\
24
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.JacksonAutoConfigurationRuntimeHints,\
35
org.springframework.boot.autoconfigure.template.TemplateRuntimeHints
46

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProviderTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21+
import org.springframework.aot.hint.RuntimeHints;
22+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
23+
import org.springframework.aot.hint.TypeHint;
24+
import org.springframework.beans.factory.aot.AotServices;
25+
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityProperties;
26+
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityRuntimeHints;
2127
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
2228
import org.springframework.core.io.DefaultResourceLoader;
2329
import org.springframework.core.io.ResourceLoader;
@@ -84,4 +90,14 @@ void availabilityOfTemplateWithCustomSuffix() {
8490
.isTrue();
8591
}
8692

93+
@Test
94+
void shouldRegisterFreeMarkerTemplateAvailabilityPropertiesRuntimeHints() {
95+
assertThat(AotServices.factories().load(RuntimeHintsRegistrar.class))
96+
.hasAtLeastOneElementOfType(FreeMarkerTemplateAvailabilityRuntimeHints.class);
97+
RuntimeHints hints = new RuntimeHints();
98+
new FreeMarkerTemplateAvailabilityRuntimeHints().registerHints(hints, getClass().getClassLoader());
99+
TypeHint typeHint = hints.reflection().getTypeHint(FreeMarkerTemplateAvailabilityProperties.class);
100+
assertThat(typeHint).isNotNull();
101+
}
102+
87103
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProviderTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21+
import org.springframework.aot.hint.RuntimeHints;
22+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
23+
import org.springframework.aot.hint.TypeHint;
24+
import org.springframework.beans.factory.aot.AotServices;
25+
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityProperties;
26+
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityRuntimeHints;
2127
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
2228
import org.springframework.core.io.DefaultResourceLoader;
2329
import org.springframework.core.io.ResourceLoader;
@@ -84,4 +90,14 @@ void availabilityOfTemplateWithCustomSuffix() {
8490
.isTrue();
8591
}
8692

93+
@Test
94+
void shouldRegisterGroovyTemplateAvailabilityPropertiesRuntimeHints() {
95+
assertThat(AotServices.factories().load(RuntimeHintsRegistrar.class))
96+
.hasAtLeastOneElementOfType(GroovyTemplateAvailabilityRuntimeHints.class);
97+
RuntimeHints hints = new RuntimeHints();
98+
new GroovyTemplateAvailabilityRuntimeHints().registerHints(hints, getClass().getClassLoader());
99+
TypeHint typeHint = hints.reflection().getTypeHint(GroovyTemplateAvailabilityProperties.class);
100+
assertThat(typeHint).isNotNull();
101+
}
102+
87103
}

0 commit comments

Comments
 (0)