Fix package tangle caused by ApplicationContextFactory
Fix package tangle by changing `ApplicationContextFactory.DEFAULT` to use `spring.factories` to discover implementations rather than needing direct access to our own `ApplicationContext` classes. Closes gh-30272
This commit is contained in:
parent
5c4b63be11
commit
77edb27a07
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,10 +19,9 @@ package org.springframework.boot;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
|
|
||||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy interface for creating the {@link ConfigurableApplicationContext} used by a
|
* Strategy interface for creating the {@link ConfigurableApplicationContext} used by a
|
||||||
|
|
@ -43,15 +42,15 @@ public interface ApplicationContextFactory {
|
||||||
*/
|
*/
|
||||||
ApplicationContextFactory DEFAULT = (webApplicationType) -> {
|
ApplicationContextFactory DEFAULT = (webApplicationType) -> {
|
||||||
try {
|
try {
|
||||||
switch (webApplicationType) {
|
for (ApplicationContextFactory candidate : SpringFactoriesLoader
|
||||||
case SERVLET:
|
.loadFactories(ApplicationContextFactory.class, ApplicationContextFactory.class.getClassLoader())) {
|
||||||
return new AnnotationConfigServletWebServerApplicationContext();
|
ConfigurableApplicationContext context = candidate.create(webApplicationType);
|
||||||
case REACTIVE:
|
if (context != null) {
|
||||||
return new AnnotationConfigReactiveWebServerApplicationContext();
|
return context;
|
||||||
default:
|
|
||||||
return new AnnotationConfigApplicationContext();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new AnnotationConfigApplicationContext();
|
||||||
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Unable create a default ApplicationContext instance, "
|
throw new IllegalStateException("Unable create a default ApplicationContext instance, "
|
||||||
+ "you may need a custom ApplicationContextFactory", ex);
|
+ "you may need a custom ApplicationContextFactory", ex);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,6 +23,9 @@ import java.util.Set;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
import org.springframework.boot.ApplicationContextFactory;
|
||||||
|
import org.springframework.boot.WebApplicationType;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigRegistry;
|
import org.springframework.context.annotation.AnnotationConfigRegistry;
|
||||||
|
|
@ -209,4 +212,18 @@ public class AnnotationConfigReactiveWebServerApplicationContext extends Reactiv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ApplicationContextFactory} registered in {@code spring.factories} to support
|
||||||
|
* {@link AnnotationConfigReactiveWebServerApplicationContext}.
|
||||||
|
*/
|
||||||
|
static class Factory implements ApplicationContextFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigurableApplicationContext create(WebApplicationType webApplicationType) {
|
||||||
|
return (webApplicationType != WebApplicationType.REACTIVE) ? null
|
||||||
|
: new AnnotationConfigReactiveWebServerApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,6 +23,9 @@ import java.util.Set;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
import org.springframework.boot.ApplicationContextFactory;
|
||||||
|
import org.springframework.boot.WebApplicationType;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||||
import org.springframework.context.annotation.AnnotationConfigRegistry;
|
import org.springframework.context.annotation.AnnotationConfigRegistry;
|
||||||
import org.springframework.context.annotation.AnnotationConfigUtils;
|
import org.springframework.context.annotation.AnnotationConfigUtils;
|
||||||
|
|
@ -206,4 +209,18 @@ public class AnnotationConfigServletWebServerApplicationContext extends ServletW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ApplicationContextFactory} registered in {@code spring.factories} to support
|
||||||
|
* {@link AnnotationConfigServletWebServerApplicationContext}.
|
||||||
|
*/
|
||||||
|
static class Factory implements ApplicationContextFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigurableApplicationContext create(WebApplicationType webApplicationType) {
|
||||||
|
return (webApplicationType != WebApplicationType.SERVLET) ? null
|
||||||
|
: new AnnotationConfigServletWebServerApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ org.springframework.boot.context.config.ConfigDataLoader=\
|
||||||
org.springframework.boot.context.config.ConfigTreeConfigDataLoader,\
|
org.springframework.boot.context.config.ConfigTreeConfigDataLoader,\
|
||||||
org.springframework.boot.context.config.StandardConfigDataLoader
|
org.springframework.boot.context.config.StandardConfigDataLoader
|
||||||
|
|
||||||
|
# Application Context Factories
|
||||||
|
org.springframework.boot.ApplicationContextFactory=\
|
||||||
|
org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext.Factory,\
|
||||||
|
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.Factory
|
||||||
|
|
||||||
# Run Listeners
|
# Run Listeners
|
||||||
org.springframework.boot.SpringApplicationRunListener=\
|
org.springframework.boot.SpringApplicationRunListener=\
|
||||||
org.springframework.boot.context.event.EventPublishingRunListener
|
org.springframework.boot.context.event.EventPublishingRunListener
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue