Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy openfeign bean registration #455

Merged
merged 2 commits into from Jan 13, 2021
Merged

Conversation

marcingrzejszczak
Copy link
Contributor

without this change we're eagerly resolving placeholder properties in passed URLs / names. Since this happens at bean definition level it's extremely early e.g. Spring Cloud Contract has not yet registered any placeholders that Feign could try to consume.
with this change we're changing the bean to become lazy initialized and we resolve the placeholder values at runtime - as late as possible.

problems:

  • one of the tests uses the factory bean - there's no more factory bean since the instance supplier for the bean registration acts as one

related issue spring-cloud/spring-cloud-contract#1303

without this change we're eagerly resolving placeholder properties in passed URLs / names. Since this happens at bean definition level it's extremely early e.g. Spring Cloud Contract has not yet registered any placeholders that Feign could try to consume.
with this change we're changing the bean to become lazy initialized and we resolve the placeholder values at runtime - as late as possible.

problems:
- one of the tests uses the factory bean - there's no more factory bean since the instance supplier for the bean registration acts as one.
@codecov
Copy link

codecov bot commented Jan 12, 2021

Codecov Report

Merging #455 (624ad04) into master (69a03ff) will decrease coverage by 0.43%.
The diff coverage is 70.21%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #455      +/-   ##
============================================
- Coverage     77.16%   76.72%   -0.44%     
- Complexity      434      436       +2     
============================================
  Files            54       54              
  Lines          1607     1633      +26     
  Branches        234      242       +8     
============================================
+ Hits           1240     1253      +13     
- Misses          252      257       +5     
- Partials        115      123       +8     
Impacted Files Coverage Δ Complexity Δ
...mework/cloud/openfeign/FeignClientFactoryBean.java 73.89% <54.54%> (-1.24%) 62.00 <9.00> (ø)
...amework/cloud/openfeign/FeignClientsRegistrar.java 77.41% <75.00%> (-2.71%) 47.00 <4.00> (+2.00) ⬇️

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

Looks good, however, I don't think it makes sense to ignore the test unless we have a plan in place to makes changes to it. We should either modify this one or create a new one or, if that's not possible, remove the existing one.

@marcingrzejszczak marcingrzejszczak changed the title Lazy openfeign bean registration WIP: Lazy openfeign bean registration Jan 12, 2021
@OlgaMaciaszek OlgaMaciaszek marked this pull request as draft January 12, 2021 15:01
@@ -47,9 +48,10 @@
"feign.client.config.default.loggerLevel=full",
"feign.client.config.default.requestInterceptors[0]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.FooRequestInterceptor",
"feign.client.config.default.requestInterceptors[1]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.BarRequestInterceptor" })
@Ignore("I don't know how to test this since the factory bean is no longer created")
Copy link
Member

Choose a reason for hiding this comment

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

Why is the factory bean no longer created?

Choose a reason for hiding this comment

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

From the initial PR comment: there's no more factory bean since the instance supplier for the bean registration acts as one

Copy link
Member

Choose a reason for hiding this comment

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

Then that class should be removed and the test removed.

@marcingrzejszczak marcingrzejszczak changed the title WIP: Lazy openfeign bean registration Lazy openfeign bean registration Jan 13, 2021
@marcingrzejszczak marcingrzejszczak added enhancement New feature or request and removed for team discussion labels Jan 13, 2021
@marcingrzejszczak marcingrzejszczak added this to In progress in 2020.0.1 via automation Jan 13, 2021
@marcingrzejszczak marcingrzejszczak added this to the 3.0.1 milestone Jan 13, 2021
@marcingrzejszczak marcingrzejszczak marked this pull request as ready for review January 13, 2021 09:14
@marcingrzejszczak marcingrzejszczak merged commit 01f101a into master Jan 13, 2021
2020.0.1 automation moved this from In progress to Done Jan 13, 2021
Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

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

LGTM

@michaldo
Copy link
Contributor

I would like you consider #443

I guess the reason is that FeignClientFactoryBean does not extend AbstractFactoryBean

Probably reusing AbstractFactoryBean patterns will decrease chance Spring-related problems

@marcingrzejszczak
Copy link
Contributor Author

But we no longer register FeignClientFactoryBean as a bean. Can you check @michaldo if with this change the problem in #443 didn't go away?

@michaldo
Copy link
Contributor

#443 still exists on 3.0.1-SNAPSHOT

It looks very suspicious to me that AbstractFactoryBean#getObject returns "early singleton proxy" and FeignClientFactoryBean#getObject returns "concrete bean". There must be a reason that base Spring class returns proxy

@OlgaMaciaszek
Copy link
Collaborator

Fixes gh-441.

OlgaMaciaszek pushed a commit that referenced this pull request Jan 20, 2021
without this change we're eagerly resolving placeholder properties in passed URLs / names. Since this happens at bean definition level it's extremely early e.g. Spring Cloud Contract has not yet registered any placeholders that Feign could try to consume.

with this change we're changing the bean to become lazy initialized and we resolve the placeholder values at runtime - as late as possible.

Fixes gh-441.
# Conflicts:
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java
@spencergibb spencergibb deleted the lazy_bean_registration branch January 4, 2022 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
2020.0.1
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants