Skip to content

Commit 3baf782

Browse files
committed
Merge branch '1.5.x' into 2.0.x
2 parents d47aaf2 + b60da5f commit 3baf782

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ private List<Annotation> getMergedAnnotations(Class<?> root, Class<?> source) {
9090
if (annotations != null) {
9191
for (Annotation annotation : annotations) {
9292
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
93-
mergedAnnotations
94-
.add(findMergedAnnotation(root, annotation.annotationType()));
93+
Annotation mergedAnnotation = findMergedAnnotation(root,
94+
annotation.annotationType());
95+
if (mergedAnnotation != null) {
96+
mergedAnnotations.add(mergedAnnotation);
97+
}
9598
}
9699
}
97100
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/examples/custom-layout.apt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</executions>
3535
<dependencies>
3636
<dependency>
37-
<groupId>com.example</groupid>
37+
<groupId>com.example</groupId>
3838
<artifactId>custom-layout</artifactId>
3939
<version>0.0.1.BUILD-SNAPSHOT</version>
4040
</dependency>

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactor
132132
beanFactory.addBeanPostProcessor(
133133
new WebApplicationContextServletContextAwareProcessor(this));
134134
beanFactory.ignoreDependencyInterface(ServletContextAware.class);
135+
registerWebApplicationScopes(null);
135136
}
136137

137138
@Override
@@ -226,19 +227,22 @@ private org.springframework.boot.web.servlet.ServletContextInitializer getSelfIn
226227

227228
private void selfInitialize(ServletContext servletContext) throws ServletException {
228229
prepareWebApplicationContext(servletContext);
229-
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
230-
ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes(
231-
beanFactory);
232-
WebApplicationContextUtils.registerWebApplicationScopes(beanFactory,
233-
getServletContext());
234-
existingScopes.restore();
235-
WebApplicationContextUtils.registerEnvironmentBeans(beanFactory,
236-
getServletContext());
230+
registerWebApplicationScopes(servletContext);
231+
WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(),
232+
servletContext);
237233
for (ServletContextInitializer beans : getServletContextInitializerBeans()) {
238234
beans.onStartup(servletContext);
239235
}
240236
}
241237

238+
private void registerWebApplicationScopes(ServletContext servletContext) {
239+
ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes(
240+
getBeanFactory());
241+
WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(),
242+
servletContext);
243+
existingScopes.restore();
244+
}
245+
242246
/**
243247
* Returns {@link ServletContextInitializer}s that should be used with the embedded
244248
* web server. By default this method will first attempt to find

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
import org.mockito.InOrder;
4040
import org.mockito.MockitoAnnotations;
4141

42+
import org.springframework.beans.BeansException;
4243
import org.springframework.beans.MutablePropertyValues;
4344
import org.springframework.beans.factory.BeanCreationException;
4445
import org.springframework.beans.factory.config.BeanDefinition;
46+
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
4547
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
4648
import org.springframework.beans.factory.config.ConstructorArgumentValues;
4749
import org.springframework.beans.factory.config.Scope;
50+
import org.springframework.beans.factory.support.AbstractBeanDefinition;
4851
import org.springframework.beans.factory.support.RootBeanDefinition;
4952
import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer;
5053
import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
@@ -449,7 +452,8 @@ public void postProcessWebServerFactory() {
449452
}
450453

451454
@Test
452-
public void doesNotReplaceExistingScopes() { // gh-2082
455+
public void doesNotReplaceExistingScopes() {
456+
// gh-2082
453457
Scope scope = mock(Scope.class);
454458
ConfigurableListableBeanFactory factory = this.context.getBeanFactory();
455459
factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope);
@@ -462,6 +466,29 @@ public void doesNotReplaceExistingScopes() { // gh-2082
462466
.isSameAs(scope);
463467
}
464468

469+
@Test
470+
public void servletRequestCanBeInjectedEarly() throws Exception {
471+
// gh-14990
472+
addWebServerFactoryBean();
473+
RootBeanDefinition beanDefinition = new RootBeanDefinition(
474+
WithAutowiredServletRequest.class);
475+
beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
476+
this.context.registerBeanDefinition("withAutowiredServletRequest",
477+
beanDefinition);
478+
this.context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
479+
480+
@Override
481+
public void postProcessBeanFactory(
482+
ConfigurableListableBeanFactory beanFactory) throws BeansException {
483+
WithAutowiredServletRequest bean = beanFactory
484+
.getBean(WithAutowiredServletRequest.class);
485+
assertThat(bean.getRequest()).isNotNull();
486+
}
487+
488+
});
489+
this.context.refresh();
490+
}
491+
465492
private void addWebServerFactoryBean() {
466493
this.context.registerBeanDefinition("webServerFactory",
467494
new RootBeanDefinition(MockServletWebServerFactory.class));
@@ -514,4 +541,18 @@ public void doFilter(ServletRequest request, ServletResponse response,
514541

515542
}
516543

544+
protected static class WithAutowiredServletRequest {
545+
546+
private final ServletRequest request;
547+
548+
public WithAutowiredServletRequest(ServletRequest request) {
549+
this.request = request;
550+
}
551+
552+
public ServletRequest getRequest() {
553+
return this.request;
554+
}
555+
556+
}
557+
517558
}

0 commit comments

Comments
 (0)