|
|
@ -98,24 +98,21 @@ import org.springframework.web.servlet.DispatcherServlet;
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
|
|
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
|
|
@ConditionalOnWebApplication
|
|
|
|
@ConditionalOnWebApplication
|
|
|
|
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class, EmbeddedServletContainerAutoConfiguration.class,
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
|
|
|
WebMvcAutoConfiguration.class, ManagementServerPropertiesAutoConfiguration.class,
|
|
|
|
ManagementServerPropertiesAutoConfiguration.class,
|
|
|
|
|
|
|
|
RepositoryRestMvcAutoConfiguration.class, HypermediaAutoConfiguration.class,
|
|
|
|
RepositoryRestMvcAutoConfiguration.class, HypermediaAutoConfiguration.class,
|
|
|
|
HttpMessageConvertersAutoConfiguration.class })
|
|
|
|
HttpMessageConvertersAutoConfiguration.class })
|
|
|
|
public class EndpointWebMvcAutoConfiguration
|
|
|
|
public class EndpointWebMvcAutoConfiguration
|
|
|
|
implements ApplicationContextAware, BeanFactoryAware, SmartInitializingSingleton {
|
|
|
|
implements ApplicationContextAware, BeanFactoryAware, SmartInitializingSingleton {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory
|
|
|
|
private static final Log logger = LogFactory.getLog(EndpointWebMvcAutoConfiguration.class);
|
|
|
|
.getLog(EndpointWebMvcAutoConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
|
|
|
|
|
|
|
private BeanFactory beanFactory;
|
|
|
|
private BeanFactory beanFactory;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext)
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
|
throws BeansException {
|
|
|
|
|
|
|
|
this.applicationContext = applicationContext;
|
|
|
|
this.applicationContext = applicationContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -130,8 +127,7 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public ManagementServletContext managementServletContext(
|
|
|
|
public ManagementServletContext managementServletContext(final ManagementServerProperties properties) {
|
|
|
|
final ManagementServerProperties properties) {
|
|
|
|
|
|
|
|
return new ManagementServletContext() {
|
|
|
|
return new ManagementServletContext() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -146,8 +142,7 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
public void afterSingletonsInstantiated() {
|
|
|
|
public void afterSingletonsInstantiated() {
|
|
|
|
ManagementServerPort managementPort = ManagementServerPort.DIFFERENT;
|
|
|
|
ManagementServerPort managementPort = ManagementServerPort.DIFFERENT;
|
|
|
|
if (this.applicationContext instanceof WebApplicationContext) {
|
|
|
|
if (this.applicationContext instanceof WebApplicationContext) {
|
|
|
|
managementPort = ManagementServerPort
|
|
|
|
managementPort = ManagementServerPort.get(this.applicationContext.getEnvironment(), this.beanFactory);
|
|
|
|
.get(this.applicationContext.getEnvironment(), this.beanFactory);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (managementPort == ManagementServerPort.DIFFERENT) {
|
|
|
|
if (managementPort == ManagementServerPort.DIFFERENT) {
|
|
|
|
if (this.applicationContext instanceof EmbeddedWebApplicationContext
|
|
|
|
if (this.applicationContext instanceof EmbeddedWebApplicationContext
|
|
|
@ -157,22 +152,17 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
logger.warn("Could not start embedded management container on "
|
|
|
|
logger.warn("Could not start embedded management container on "
|
|
|
|
+ "different port (management endpoints are still available "
|
|
|
|
+ "different port (management endpoints are still available " + "through JMX)");
|
|
|
|
+ "through JMX)");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (managementPort == ManagementServerPort.SAME) {
|
|
|
|
if (managementPort == ManagementServerPort.SAME) {
|
|
|
|
if (new RelaxedPropertyResolver(this.applicationContext.getEnvironment(),
|
|
|
|
if (new RelaxedPropertyResolver(this.applicationContext.getEnvironment(), "management.ssl.")
|
|
|
|
"management.ssl.").getProperty("enabled", Boolean.class, false)) {
|
|
|
|
.getProperty("enabled", Boolean.class, false)) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException("Management-specific SSL cannot be configured as the management "
|
|
|
|
"Management-specific SSL cannot be configured as the management "
|
|
|
|
|
|
|
|
+ "server is not listening on a separate port");
|
|
|
|
+ "server is not listening on a separate port");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.applicationContext
|
|
|
|
if (this.applicationContext.getEnvironment() instanceof ConfigurableEnvironment) {
|
|
|
|
.getEnvironment() instanceof ConfigurableEnvironment) {
|
|
|
|
addLocalManagementPortPropertyAlias((ConfigurableEnvironment) this.applicationContext.getEnvironment());
|
|
|
|
addLocalManagementPortPropertyAlias(
|
|
|
|
|
|
|
|
(ConfigurableEnvironment) this.applicationContext
|
|
|
|
|
|
|
|
.getEnvironment());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -183,26 +173,21 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
childContext.setNamespace("management");
|
|
|
|
childContext.setNamespace("management");
|
|
|
|
childContext.setId(this.applicationContext.getId() + ":management");
|
|
|
|
childContext.setId(this.applicationContext.getId() + ":management");
|
|
|
|
childContext.setClassLoader(this.applicationContext.getClassLoader());
|
|
|
|
childContext.setClassLoader(this.applicationContext.getClassLoader());
|
|
|
|
childContext.register(EndpointWebMvcChildContextConfiguration.class,
|
|
|
|
childContext.register(EndpointWebMvcChildContextConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class, DispatcherServletAutoConfiguration.class);
|
|
|
|
EmbeddedServletContainerAutoConfiguration.class,
|
|
|
|
|
|
|
|
DispatcherServletAutoConfiguration.class);
|
|
|
|
|
|
|
|
registerEmbeddedServletContainerFactory(childContext);
|
|
|
|
registerEmbeddedServletContainerFactory(childContext);
|
|
|
|
CloseManagementContextListener.addIfPossible(this.applicationContext,
|
|
|
|
CloseManagementContextListener.addIfPossible(this.applicationContext, childContext);
|
|
|
|
childContext);
|
|
|
|
|
|
|
|
childContext.refresh();
|
|
|
|
childContext.refresh();
|
|
|
|
managementContextResolver().setApplicationContext(childContext);
|
|
|
|
managementContextResolver().setApplicationContext(childContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerEmbeddedServletContainerFactory(
|
|
|
|
private void registerEmbeddedServletContainerFactory(AnnotationConfigEmbeddedWebApplicationContext childContext) {
|
|
|
|
AnnotationConfigEmbeddedWebApplicationContext childContext) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
|
|
|
|
ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
|
|
|
|
if (beanFactory instanceof BeanDefinitionRegistry) {
|
|
|
|
if (beanFactory instanceof BeanDefinitionRegistry) {
|
|
|
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
|
|
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
|
|
|
|
registry.registerBeanDefinition("embeddedServletContainerFactory",
|
|
|
|
registry.registerBeanDefinition("embeddedServletContainerFactory",
|
|
|
|
new RootBeanDefinition(
|
|
|
|
new RootBeanDefinition(determineEmbeddedServletContainerFactoryClass()));
|
|
|
|
determineEmbeddedServletContainerFactoryClass()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NoSuchBeanDefinitionException ex) {
|
|
|
|
catch (NoSuchBeanDefinitionException ex) {
|
|
|
@ -210,10 +195,9 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Class<?> determineEmbeddedServletContainerFactoryClass()
|
|
|
|
private Class<?> determineEmbeddedServletContainerFactoryClass() throws NoSuchBeanDefinitionException {
|
|
|
|
throws NoSuchBeanDefinitionException {
|
|
|
|
Class<?> servletContainerFactoryClass = this.applicationContext.getBean(EmbeddedServletContainerFactory.class)
|
|
|
|
Class<?> servletContainerFactoryClass = this.applicationContext
|
|
|
|
.getClass();
|
|
|
|
.getBean(EmbeddedServletContainerFactory.class).getClass();
|
|
|
|
|
|
|
|
if (cannotBeInstantiated(servletContainerFactoryClass)) {
|
|
|
|
if (cannotBeInstantiated(servletContainerFactoryClass)) {
|
|
|
|
throw new FatalBeanException("EmbeddedServletContainerFactory implementation "
|
|
|
|
throw new FatalBeanException("EmbeddedServletContainerFactory implementation "
|
|
|
|
+ servletContainerFactoryClass.getName() + " cannot be instantiated. "
|
|
|
|
+ servletContainerFactoryClass.getName() + " cannot be instantiated. "
|
|
|
@ -224,8 +208,7 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean cannotBeInstantiated(Class<?> clazz) {
|
|
|
|
private boolean cannotBeInstantiated(Class<?> clazz) {
|
|
|
|
return clazz.isLocalClass()
|
|
|
|
return clazz.isLocalClass() || (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers()))
|
|
|
|
|| (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers()))
|
|
|
|
|
|
|
|
|| clazz.isAnonymousClass();
|
|
|
|
|| clazz.isAnonymousClass();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -234,10 +217,8 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
* 'local.server.port'.
|
|
|
|
* 'local.server.port'.
|
|
|
|
* @param environment the environment
|
|
|
|
* @param environment the environment
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void addLocalManagementPortPropertyAlias(
|
|
|
|
private void addLocalManagementPortPropertyAlias(final ConfigurableEnvironment environment) {
|
|
|
|
final ConfigurableEnvironment environment) {
|
|
|
|
environment.getPropertySources().addLast(new PropertySource<Object>("Management Server") {
|
|
|
|
environment.getPropertySources()
|
|
|
|
|
|
|
|
.addLast(new PropertySource<Object>("Management Server") {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Object getProperty(String name) {
|
|
|
|
public Object getProperty(String name) {
|
|
|
|
if ("local.management.port".equals(name)) {
|
|
|
|
if ("local.management.port".equals(name)) {
|
|
|
@ -251,13 +232,12 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
// Put Servlets and Filters in their own nested class so they don't force early
|
|
|
|
// Put Servlets and Filters in their own nested class so they don't force early
|
|
|
|
// instantiation of ManagementServerProperties.
|
|
|
|
// instantiation of ManagementServerProperties.
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@ConditionalOnProperty(prefix = "management", name = "add-application-context-header",
|
|
|
|
@ConditionalOnProperty(prefix = "management", name = "add-application-context-header", matchIfMissing = true,
|
|
|
|
matchIfMissing = true, havingValue = "true")
|
|
|
|
havingValue = "true")
|
|
|
|
protected static class ApplicationContextFilterConfiguration {
|
|
|
|
protected static class ApplicationContextFilterConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public ApplicationContextHeaderFilter applicationContextIdFilter(
|
|
|
|
public ApplicationContextHeaderFilter applicationContextIdFilter(ApplicationContext context) {
|
|
|
|
ApplicationContext context) {
|
|
|
|
|
|
|
|
return new ApplicationContextHeaderFilter(context);
|
|
|
|
return new ApplicationContextHeaderFilter(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -274,15 +254,13 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
* {@link ApplicationListener} to propagate the {@link ContextClosedEvent} and
|
|
|
|
* {@link ApplicationListener} to propagate the {@link ContextClosedEvent} and
|
|
|
|
* {@link ApplicationFailedEvent} from a parent to a child.
|
|
|
|
* {@link ApplicationFailedEvent} from a parent to a child.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static class CloseManagementContextListener
|
|
|
|
private static class CloseManagementContextListener implements ApplicationListener<ApplicationEvent> {
|
|
|
|
implements ApplicationListener<ApplicationEvent> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ApplicationContext parentContext;
|
|
|
|
private final ApplicationContext parentContext;
|
|
|
|
|
|
|
|
|
|
|
|
private final ConfigurableApplicationContext childContext;
|
|
|
|
private final ConfigurableApplicationContext childContext;
|
|
|
|
|
|
|
|
|
|
|
|
CloseManagementContextListener(ApplicationContext parentContext,
|
|
|
|
CloseManagementContextListener(ApplicationContext parentContext, ConfigurableApplicationContext childContext) {
|
|
|
|
ConfigurableApplicationContext childContext) {
|
|
|
|
|
|
|
|
this.parentContext = parentContext;
|
|
|
|
this.parentContext = parentContext;
|
|
|
|
this.childContext = childContext;
|
|
|
|
this.childContext = childContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,14 +298,12 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
|
|
|
|
|
|
|
|
private static void add(ConfigurableApplicationContext parentContext,
|
|
|
|
private static void add(ConfigurableApplicationContext parentContext,
|
|
|
|
ConfigurableApplicationContext childContext) {
|
|
|
|
ConfigurableApplicationContext childContext) {
|
|
|
|
parentContext.addApplicationListener(
|
|
|
|
parentContext.addApplicationListener(new CloseManagementContextListener(parentContext, childContext));
|
|
|
|
new CloseManagementContextListener(parentContext, childContext));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class OnManagementMvcCondition extends SpringBootCondition
|
|
|
|
private static class OnManagementMvcCondition extends SpringBootCondition implements ConfigurationCondition {
|
|
|
|
implements ConfigurationCondition {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ConfigurationPhase getConfigurationPhase() {
|
|
|
|
public ConfigurationPhase getConfigurationPhase() {
|
|
|
@ -335,16 +311,12 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
|
|
|
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
|
|
|
AnnotatedTypeMetadata metadata) {
|
|
|
|
ConditionMessage.Builder message = ConditionMessage.forCondition("Management Server MVC");
|
|
|
|
ConditionMessage.Builder message = ConditionMessage
|
|
|
|
|
|
|
|
.forCondition("Management Server MVC");
|
|
|
|
|
|
|
|
if (!(context.getResourceLoader() instanceof WebApplicationContext)) {
|
|
|
|
if (!(context.getResourceLoader() instanceof WebApplicationContext)) {
|
|
|
|
return ConditionOutcome
|
|
|
|
return ConditionOutcome.noMatch(message.because("non WebApplicationContext"));
|
|
|
|
.noMatch(message.because("non WebApplicationContext"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ManagementServerPort port = ManagementServerPort.get(context.getEnvironment(),
|
|
|
|
ManagementServerPort port = ManagementServerPort.get(context.getEnvironment(), context.getBeanFactory());
|
|
|
|
context.getBeanFactory());
|
|
|
|
|
|
|
|
if (port == ManagementServerPort.SAME) {
|
|
|
|
if (port == ManagementServerPort.SAME) {
|
|
|
|
return ConditionOutcome.match(message.because("port is same"));
|
|
|
|
return ConditionOutcome.match(message.because("port is same"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -357,28 +329,22 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
|
|
|
|
|
|
|
|
DISABLE, SAME, DIFFERENT;
|
|
|
|
DISABLE, SAME, DIFFERENT;
|
|
|
|
|
|
|
|
|
|
|
|
public static ManagementServerPort get(Environment environment,
|
|
|
|
public static ManagementServerPort get(Environment environment, BeanFactory beanFactory) {
|
|
|
|
BeanFactory beanFactory) {
|
|
|
|
|
|
|
|
Integer serverPort = getPortProperty(environment, "server.");
|
|
|
|
Integer serverPort = getPortProperty(environment, "server.");
|
|
|
|
if (serverPort == null && hasCustomBeanDefinition(beanFactory,
|
|
|
|
if (serverPort == null && hasCustomBeanDefinition(beanFactory, ServerProperties.class,
|
|
|
|
ServerProperties.class, ServerPropertiesAutoConfiguration.class)) {
|
|
|
|
ServerPropertiesAutoConfiguration.class)) {
|
|
|
|
serverPort = getTemporaryBean(beanFactory, ServerProperties.class)
|
|
|
|
serverPort = getTemporaryBean(beanFactory, ServerProperties.class).getPort();
|
|
|
|
.getPort();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Integer managementPort = getPortProperty(environment, "management.");
|
|
|
|
Integer managementPort = getPortProperty(environment, "management.");
|
|
|
|
if (managementPort == null && hasCustomBeanDefinition(beanFactory,
|
|
|
|
if (managementPort == null && hasCustomBeanDefinition(beanFactory, ManagementServerProperties.class,
|
|
|
|
ManagementServerProperties.class,
|
|
|
|
|
|
|
|
ManagementServerPropertiesAutoConfiguration.class)) {
|
|
|
|
ManagementServerPropertiesAutoConfiguration.class)) {
|
|
|
|
managementPort = getTemporaryBean(beanFactory,
|
|
|
|
managementPort = getTemporaryBean(beanFactory, ManagementServerProperties.class).getPort();
|
|
|
|
ManagementServerProperties.class).getPort();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (managementPort != null && managementPort < 0) {
|
|
|
|
if (managementPort != null && managementPort < 0) {
|
|
|
|
return DISABLE;
|
|
|
|
return DISABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ((managementPort == null)
|
|
|
|
return ((managementPort == null) || (serverPort == null && managementPort.equals(8080))
|
|
|
|
|| (serverPort == null && managementPort.equals(8080))
|
|
|
|
|| (managementPort != 0) && managementPort.equals(serverPort)) ? SAME : DIFFERENT;
|
|
|
|
|| (managementPort != 0) && managementPort.equals(serverPort)) ? SAME
|
|
|
|
|
|
|
|
: DIFFERENT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> T getTemporaryBean(BeanFactory beanFactory, Class<T> type) {
|
|
|
|
private static <T> T getTemporaryBean(BeanFactory beanFactory, Class<T> type) {
|
|
|
@ -392,35 +358,30 @@ public class EndpointWebMvcAutoConfiguration
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Use a temporary child bean factory to avoid instantiating the bean in the
|
|
|
|
// Use a temporary child bean factory to avoid instantiating the bean in the
|
|
|
|
// parent (it won't be bound to the environment yet)
|
|
|
|
// parent (it won't be bound to the environment yet)
|
|
|
|
return createTemporaryBean(type, listable,
|
|
|
|
return createTemporaryBean(type, listable, listable.getBeanDefinition(names[0]));
|
|
|
|
listable.getBeanDefinition(names[0]));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> T createTemporaryBean(Class<T> type,
|
|
|
|
private static <T> T createTemporaryBean(Class<T> type, ConfigurableListableBeanFactory parent,
|
|
|
|
ConfigurableListableBeanFactory parent, BeanDefinition definition) {
|
|
|
|
BeanDefinition definition) {
|
|
|
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(
|
|
|
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(parent);
|
|
|
|
parent);
|
|
|
|
|
|
|
|
beanFactory.registerBeanDefinition(type.getName(), definition);
|
|
|
|
beanFactory.registerBeanDefinition(type.getName(), definition);
|
|
|
|
return beanFactory.getBean(type);
|
|
|
|
return beanFactory.getBean(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Integer getPortProperty(Environment environment, String prefix) {
|
|
|
|
private static Integer getPortProperty(Environment environment, String prefix) {
|
|
|
|
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
|
|
|
|
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, prefix);
|
|
|
|
prefix);
|
|
|
|
|
|
|
|
return resolver.getProperty("port", Integer.class);
|
|
|
|
return resolver.getProperty("port", Integer.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> boolean hasCustomBeanDefinition(BeanFactory beanFactory,
|
|
|
|
private static <T> boolean hasCustomBeanDefinition(BeanFactory beanFactory, Class<T> type,
|
|
|
|
Class<T> type, Class<?> configClass) {
|
|
|
|
Class<?> configClass) {
|
|
|
|
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
|
|
|
|
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasCustomBeanDefinition((ConfigurableListableBeanFactory) beanFactory,
|
|
|
|
return hasCustomBeanDefinition((ConfigurableListableBeanFactory) beanFactory, type, configClass);
|
|
|
|
type, configClass);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> boolean hasCustomBeanDefinition(
|
|
|
|
private static <T> boolean hasCustomBeanDefinition(ConfigurableListableBeanFactory beanFactory, Class<T> type,
|
|
|
|
ConfigurableListableBeanFactory beanFactory, Class<T> type,
|
|
|
|
|
|
|
|
Class<?> configClass) {
|
|
|
|
Class<?> configClass) {
|
|
|
|
String[] names = beanFactory.getBeanNamesForType(type, true, false);
|
|
|
|
String[] names = beanFactory.getBeanNamesForType(type, true, false);
|
|
|
|
if (names == null || names.length != 1) {
|
|
|
|
if (names == null || names.length != 1) {
|
|
|
|