Skip to content

Support Spring Cloud InetUtils for client registration - #4600

Open
myProjectsRavi wants to merge 2 commits into
codecentric:masterfrom
myProjectsRavi:feature/issue-1323-inetutils-support
Open

myProjectsRavi wants to merge 2 commits into
codecentric:masterfrom
myProjectsRavi:feature/issue-1323-inetutils-support

Conversation

@myProjectsRavi

@myProjectsRavi myProjectsRavi commented Aug 27, 2025 •

Copy link
Copy Markdown

Use Spring Cloud's InetUtils to select the local registration address when an InetUtils bean is available, so clients can honor spring.cloud.inetutils.* settings.

  • Add conditional servlet and reactive application factories that call findFirstNonLoopbackAddress() directly.
  • Keep Spring Cloud optional and leave the existing default factories unchanged. Fall back to the default host lookup if InetUtils returns no address.
  • Preserve explicit URLs, configured addresses, servlet and reactive paths, management ports, SSL, and metadata. Custom factories and Cloud Foundry retain precedence.
  • Add tests for address selection, fallback, auto-configuration, and existing registration behavior, plus configuration documentation.

Validation: ./mvnw -B -ntp -DdisableSpringSnapshots -pl spring-boot-admin-client -am clean verify passes on Java 17: 124 tests, no failures, errors, or skipped tests. Checkstyle, Spring Java Format, and Javadoc generation pass. The existing registration integration tests explicitly use the default factories so their expected host does not depend on InetUtils selecting the same local interface.

Closes #1323.

@myProjectsRavi
myProjectsRavi requested a review from a team as a code owner August 27, 2025 08:52

@erikpetzold erikpetzold left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not yet have a look at the changes in detail yet, but please clean up the PR

Comment thread spring-boot-admin-samples/spring-boot-admin-sample-oauth2-client/pom.xml Outdated
@ozkanpakdil

Copy link
Copy Markdown
Contributor

Thanks for picking this up — #1323 is a real gap and the intent here is right. I went through the diff and the linked issue, and one functional bug stands out along with a few smaller items. Happy to help with any of it.

The InetUtils branch never executes

In DefaultApplicationFactory.java:

Method m = utils.getClass().getMethod("findFirstNonLoopbackHostInfo");
Object host = m.invoke(utils);
if (host instanceof String && StringUtils.hasText((String) host)) {

findFirstNonLoopbackHostInfo() returns InetUtils.HostInfo, not String:

$ javap -cp spring-cloud-commons-5.0.3.jar org.springframework.cloud.commons.util.InetUtils
public org.springframework.cloud.commons.util.InetUtils$HostInfo findFirstNonLoopbackHostInfo();
public java.net.InetAddress findFirstNonLoopbackAddress();

Checked 4.1.4, 4.2.0, 4.3.0, 5.0.1 and 5.0.3 — all HostInfo. So host instanceof String is always false, the branch falls through to InetAddress.getLocalHost(), and no spring.cloud.inetutils.* setting has any effect. For getLocalHost(), findFirstNonLoopbackAddress() is the natural call — it returns an InetAddress straight away, and it's what the snippet in #1323 uses.

Likely shape

On #1323 @joshiste suggested "a special ApplicationFactory that will be autoconfigured when the InetUtils are present", since the client also has to work without Spring Cloud. CloudFoundryApplicationFactory together with SpringBootAdminClientCloudFoundryAutoConfiguration is the existing precedent for that — a conditional bean plus @AutoConfigureBefore(SpringBootAdminClientAutoConfiguration.class), leaving DefaultApplicationFactory untouched.

Smaller items

  • The OAuth2 sample modules (13 of the 18 files) look like a separate feature and would probably be better as their own PR.
  • spring-boot-admin-samples/pom.xml drops spring-boot-admin-sample-servlet from <modules>, which takes an existing sample out of the build — intended?
  • DefaultApplicationFactory.java:49 — the "Removed InetUtils dependency" comment doesn't describe anything in the diff.
  • getHost() — the switch expression → switch statement change is unrelated to the feature.
  • getLocalHost() — IllegalArgumentException → IllegalStateException changes existing behavior; unrelated, probably best left as-is.
  • No tests yet; DefaultApplicationFactoryTest / ServletApplicationFactoryTest / ReactiveApplicationFactoryTest are the natural spots for a findFirstNonLoopbackAddress() case.
  • The branch needs a rebase onto current master (it currently reports conflicts).

If it's useful, I'm glad to open a superseding PR in the shape above (conditional InetUtilsApplicationFactory + tests), with you credited, or hand you the patch so it stays your PR — whichever you'd prefer.

Use conditional servlet and reactive factories for host resolution.
Keep Spring Cloud optional and preserve existing URL handling.

Closes codecentric#1323.
@myProjectsRavi
myProjectsRavi force-pushed the feature/issue-1323-inetutils-support branch from b1073ce to 2aba8e1 Compare October 4, 2026 04:54
@myProjectsRavi myProjectsRavi changed the title Feature/issue 1323 inetutils support Support Spring Cloud InetUtils for client registration Oct 4, 2026
Exclude InetUtils auto-configuration from tests that expect the default local host lookup.
@myProjectsRavi

Copy link
Copy Markdown
Author

Addressed the review feedback and rebased this PR onto the current master.
The PR is now limited to the InetUtils change. The unrelated sample/default factory changes and reflection-based implementation have been removed, findFirstNonLoopbackAddress() is used directly, Spring Cloud remains optional, and servlet/reactive, fallback, precedence, and regression cases are covered by tests.
The branch is up to date with master, mergeable, and all previous review threads are resolved/outdated.
Could a maintainer please approve the pending workflow and take another look?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support of spring InetUtils in DefaultApplicationFactory

4 participants