Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Oct 13, 2023
2 parents 60f05ea + 0c1b5d1 commit 085e12a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ private String determineName(Map<String, Object> attributes, BeanDefinition bean
: 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

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}
Expand Down Expand Up @@ -158,6 +159,16 @@ void processAheadOfTimeRegistersReflectionHintsForWebListeners() {
.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(
Expand Down Expand Up @@ -215,4 +226,10 @@ static class ScanListenerPackage {

}

@Configuration(proxyBeanMethods = false)
@ServletComponentScan("org.springframework.boot.web.servlet.testcomponents.servlet")
static class ScanServletPackage {

}

}

0 comments on commit 085e12a

Please sign in to comment.