Skip to content

[BUG] useFeignClientContextId default option causes IllegalStateException at runtime #21521

Open
@moreginger

Description

@moreginger

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Following the introduction of useFeignCleintContextId with default true in #20943, the contextId by default fails to resolve a valid service name and throws an exception, e.g.:

Service id not legal hostname (${countries.name})
java.lang.IllegalStateException: Service id not legal hostname (${countries.name})
	at org.springframework.util.Assert.state(Assert.java:79)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.getName(FeignClientsRegistrar.java:111)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.getContextId(FeignClientsRegistrar.java:346)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.eagerlyRegisterFeignClientBeanDefinition(FeignClientsRegistrar.java:230)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClient(FeignClientsRegistrar.java:215)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClients(FeignClientsRegistrar.java:204)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerBeanDefinitions(FeignClientsRegistrar.java:154)
	at org.springframework.context.annotation.ImportBeanDefinitionRegistrar.registerBeanDefinitions(ImportBeanDefinitionRegistrar.java:86)

This is with org.springframework.cloud:spring-cloud-starter-openfeign:4.3.0

The generated feign client looks like this:

@FeignClient(name="${countries.name:countries}", contextId="${countries.contextId:${countries.name}}",  configuration = ClientConfiguration.class)
public interface CountriesApiClient extends CountriesApi {
}
openapi-generator version

7.13.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs

#20943

Suggest a fix

Is it possible for the contextId to actually resolve the nested countries.name expression or is it doomed to fail? In any case, I think it would be better to default this new option to false rather than true.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions