Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spring-boot-admin-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<artifactId>spring-boot-starter-webmvc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2014-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.codecentric.boot.admin.client.config;

import java.util.Collections;
import java.util.List;

import jakarta.servlet.ServletContext;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
import org.springframework.boot.webflux.autoconfigure.WebFluxProperties;
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletPath;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import de.codecentric.boot.admin.client.registration.ApplicationFactory;
import de.codecentric.boot.admin.client.registration.InetUtilsReactiveApplicationFactory;
import de.codecentric.boot.admin.client.registration.InetUtilsServletApplicationFactory;
import de.codecentric.boot.admin.client.registration.metadata.CompositeMetadataContributor;
import de.codecentric.boot.admin.client.registration.metadata.MetadataContributor;

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication
@ConditionalOnClass(InetUtils.class)
@ConditionalOnBean(InetUtils.class)
@Conditional(SpringBootAdminClientEnabledCondition.class)
@AutoConfigureAfter({ UtilAutoConfiguration.class, SpringBootAdminClientCloudFoundryAutoConfiguration.class })
@AutoConfigureBefore(SpringBootAdminClientAutoConfiguration.class)
public class SpringBootAdminClientInetUtilsAutoConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.SERVLET)
public static class ServletConfiguration {

@Bean
@Lazy(false)
@ConditionalOnMissingBean(ApplicationFactory.class)
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
WebEndpointProperties webEndpoint, ObjectProvider<List<MetadataContributor>> metadataContributors,
DispatcherServletPath dispatcherServletPath, InetUtils inetUtils) {
return new InetUtilsServletApplicationFactory(instance, management, server, servletContext,
pathMappedEndpoints, webEndpoint,
new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
dispatcherServletPath, inetUtils);
}

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.REACTIVE)
public static class ReactiveConfiguration {

@Bean
@Lazy(false)
@ConditionalOnMissingBean(ApplicationFactory.class)
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
ObjectProvider<List<MetadataContributor>> metadataContributors, WebFluxProperties webFluxProperties,
InetUtils inetUtils) {
return new InetUtilsReactiveApplicationFactory(instance, management, server, pathMappedEndpoints,
webEndpoint,
new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
webFluxProperties, inetUtils);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2014-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.codecentric.boot.admin.client.registration;

import java.net.InetAddress;

import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
import org.springframework.boot.webflux.autoconfigure.WebFluxProperties;
import org.springframework.cloud.commons.util.InetUtils;

import de.codecentric.boot.admin.client.config.InstanceProperties;
import de.codecentric.boot.admin.client.registration.metadata.MetadataContributor;

public class InetUtilsReactiveApplicationFactory extends ReactiveApplicationFactory {

private final InetUtils inetUtils;

public InetUtilsReactiveApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
MetadataContributor metadataContributor, WebFluxProperties webFluxProperties, InetUtils inetUtils) {
super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor, webFluxProperties);
this.inetUtils = inetUtils;
}

@Override
protected InetAddress getLocalHost() {
InetAddress address = this.inetUtils.findFirstNonLoopbackAddress();
return (address != null) ? address : super.getLocalHost();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2014-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.codecentric.boot.admin.client.registration;

import java.net.InetAddress;

import jakarta.servlet.ServletContext;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletPath;
import org.springframework.cloud.commons.util.InetUtils;

import de.codecentric.boot.admin.client.config.InstanceProperties;
import de.codecentric.boot.admin.client.registration.metadata.MetadataContributor;

public class InetUtilsServletApplicationFactory extends ServletApplicationFactory {

private final InetUtils inetUtils;

public InetUtilsServletApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
WebEndpointProperties webEndpoint, MetadataContributor metadataContributor,
DispatcherServletPath dispatcherServletPath, InetUtils inetUtils) {
super(instance, management, server, servletContext, pathMappedEndpoints, webEndpoint, metadataContributor,
dispatcherServletPath);
this.inetUtils = inetUtils;
}

@Override
protected InetAddress getLocalHost() {
InetAddress address = this.inetUtils.findFirstNonLoopbackAddress();
return (address != null) ? address : super.getLocalHost();
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration
de.codecentric.boot.admin.client.config.SpringBootAdminClientCloudFoundryAutoConfiguration
de.codecentric.boot.admin.client.config.SpringBootAdminClientInetUtilsAutoConfiguration
de.codecentric.boot.admin.client.config.SpringNativeClientAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.EventListener;

import de.codecentric.boot.admin.client.config.SpringBootAdminClientInetUtilsAutoConfiguration;
import de.codecentric.boot.admin.client.registration.ApplicationRegistrator;

import static com.github.tomakehurst.wiremock.client.WireMock.created;
Expand Down Expand Up @@ -144,7 +145,7 @@ private int getManagementPort() {
}

@SpringBootConfiguration
@EnableAutoConfiguration
@EnableAutoConfiguration(exclude = SpringBootAdminClientInetUtilsAutoConfiguration.class)
public static class TestClientApplication {

@Autowired
Expand Down
Loading