Merge branch '3.1.x'

Closes gh-37884
This commit is contained in:
Andy Wilkinson 2023-10-13 16:39:21 +01:00
commit 085e12aa93
2 changed files with 24 additions and 3 deletions

View File

@ -59,14 +59,18 @@ class WebServletHandler extends ServletComponentHandler {
: beanDefinition.getBeanClassName());
}
private MultipartConfigElement determineMultipartConfig(AnnotatedBeanDefinition beanDefinition) {
private BeanDefinition determineMultipartConfig(AnnotatedBeanDefinition beanDefinition) {
Map<String, Object> attributes = beanDefinition.getMetadata()
.getAnnotationAttributes(MultipartConfig.class.getName());
if (attributes == null) {
return null;
}
return new MultipartConfigElement((String) attributes.get("location"), (Long) attributes.get("maxFileSize"),
(Long) attributes.get("maxRequestSize"), (Integer) attributes.get("fileSizeThreshold"));
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(MultipartConfigElement.class);
builder.addConstructorArgValue(attributes.get("location"));
builder.addConstructorArgValue(attributes.get("maxFileSize"));
builder.addConstructorArgValue(attributes.get("maxRequestSize"));
builder.addConstructorArgValue(attributes.get("fileSizeThreshold"));
return builder.getBeanDefinition();
}
}

View File

@ -39,6 +39,7 @@ import org.springframework.javapoet.ClassName;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNoException;
/**
* Tests for {@link ServletComponentScanRegistrar}
@ -158,6 +159,16 @@ class ServletComponentScanRegistrarTests {
.accepts(generationContext.getRuntimeHints());
}
@Test
void processAheadOfTimeSucceedsForWebServletWithMultipartConfig() {
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
context.registerBean(ScanServletPackage.class);
TestGenerationContext generationContext = new TestGenerationContext(
ClassName.get(getClass().getPackageName(), "TestTarget"));
assertThatNoException()
.isThrownBy(() -> new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext));
}
@SuppressWarnings("unchecked")
private void compile(GenericApplicationContext context, Consumer<GenericApplicationContext> freshContext) {
TestGenerationContext generationContext = new TestGenerationContext(
@ -215,4 +226,10 @@ class ServletComponentScanRegistrarTests {
}
@Configuration(proxyBeanMethods = false)
@ServletComponentScan("org.springframework.boot.web.servlet.testcomponents.servlet")
static class ScanServletPackage {
}
}