Skip to content

Commit 085e12a

Browse files
committed
Merge branch '3.1.x'
Closes gh-37884
2 parents 60f05ea + 0c1b5d1 commit 085e12a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/WebServletHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@ private String determineName(Map<String, Object> attributes, BeanDefinition bean
5959
: beanDefinition.getBeanClassName());
6060
}
6161

62-
private MultipartConfigElement determineMultipartConfig(AnnotatedBeanDefinition beanDefinition) {
62+
private BeanDefinition determineMultipartConfig(AnnotatedBeanDefinition beanDefinition) {
6363
Map<String, Object> attributes = beanDefinition.getMetadata()
6464
.getAnnotationAttributes(MultipartConfig.class.getName());
6565
if (attributes == null) {
6666
return null;
6767
}
68-
return new MultipartConfigElement((String) attributes.get("location"), (Long) attributes.get("maxFileSize"),
69-
(Long) attributes.get("maxRequestSize"), (Integer) attributes.get("fileSizeThreshold"));
68+
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(MultipartConfigElement.class);
69+
builder.addConstructorArgValue(attributes.get("location"));
70+
builder.addConstructorArgValue(attributes.get("maxFileSize"));
71+
builder.addConstructorArgValue(attributes.get("maxRequestSize"));
72+
builder.addConstructorArgValue(attributes.get("fileSizeThreshold"));
73+
return builder.getBeanDefinition();
7074
}
7175

7276
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanRegistrarTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import static org.assertj.core.api.Assertions.assertThat;
4141
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
42+
import static org.assertj.core.api.Assertions.assertThatNoException;
4243

4344
/**
4445
* Tests for {@link ServletComponentScanRegistrar}
@@ -158,6 +159,16 @@ void processAheadOfTimeRegistersReflectionHintsForWebListeners() {
158159
.accepts(generationContext.getRuntimeHints());
159160
}
160161

162+
@Test
163+
void processAheadOfTimeSucceedsForWebServletWithMultipartConfig() {
164+
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
165+
context.registerBean(ScanServletPackage.class);
166+
TestGenerationContext generationContext = new TestGenerationContext(
167+
ClassName.get(getClass().getPackageName(), "TestTarget"));
168+
assertThatNoException()
169+
.isThrownBy(() -> new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext));
170+
}
171+
161172
@SuppressWarnings("unchecked")
162173
private void compile(GenericApplicationContext context, Consumer<GenericApplicationContext> freshContext) {
163174
TestGenerationContext generationContext = new TestGenerationContext(
@@ -215,4 +226,10 @@ static class ScanListenerPackage {
215226

216227
}
217228

229+
@Configuration(proxyBeanMethods = false)
230+
@ServletComponentScan("org.springframework.boot.web.servlet.testcomponents.servlet")
231+
static class ScanServletPackage {
232+
233+
}
234+
218235
}

0 commit comments

Comments
 (0)