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

fix(spring): allow bean injection by constructor #126

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

michel-barret
Copy link
Contributor

@michel-barret michel-barret commented Oct 1, 2024

Issue

https://gravitee.atlassian.net/browse/APIM-7022

Description

Allow to instanciate this type of bean StatusProbe

  • fully rely on Spring to instanciate beans (by constructors, fields or any else)
  • spring already inject ApplicationContext if need
  • should allow usage of @PostConstruct
  • use more simple function to get all beans for a type

Gravitee.io Automatic Deployment

🚀 A prerelease version of this package has been published on Gravitee's private artifactory, you can:

  • use it directly by updating your project with version: 4.6.0-apim-7022-SpringFactories-instanciates-beans-SNAPSHOT
  • download it from Artifactory here

@michel-barret michel-barret marked this pull request as ready for review October 2, 2024 07:23
@michel-barret michel-barret requested a review from a team as a code owner October 2, 2024 07:23
@michel-barret
Copy link
Contributor Author

I have test it against:

  • agents of federation
  • APIM
  • gateway

} else {
logger.debug("Instances for type {} already loaded. Skipping...", getObjectType().getName());
}

return factories;
}

private Collection<? extends T> getSpringFactoriesInstances(Class<T> type, Class<?>[] parameterTypes, Object... args) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a specific mechanism for loading classes and beans for plugins. By removing this part you may break the plugin spring beans loading, inheritance, and separations. Are you able to confirm/infirm this in some way ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is why I try multiples deployments. I haven't a global view on how it's used in gravitee. I don't know make more tests.

I make this part only to cleanup the file (don't use deprecated method), but I can reduce the changeset to the minimum to be more confident

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have splited in 2 commits one with minimal fix and another with improvments

Allow to instanciate this type of bean https://github.com/gravitee-io/gravitee-federation-agent/blob/2.7.1/gravitee-federation-agent-standalone/gravitee-federation-agent-standalone-container/src/main/java/com/graviteesource/integration/agent/standalone/probes/StatusProbe.java

- fully rely on Spring to instanciate beans (by constructors, fields or any else)
- spring already inject ApplicationContext if need
- should allow usage of @PostConstruct
- use more simple function to get all beans for a type

APIM-7022
@michel-barret michel-barret force-pushed the apim-7022-SpringFactories-instanciates-beans branch from a7ac22b to 0516a07 Compare October 8, 2024 12:30
@michel-barret
Copy link
Contributor Author

I will make more integration tests on each implementations of SpringFactoriesLoader can be found here:
https://github.com/search?q=org%3Agravitee-io%20io.gravitee.common.spring.factory.SpringFactoriesLoader&type=code

I put the PR in draft until I will make it

@michel-barret michel-barret marked this pull request as draft October 9, 2024 13:38
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.

2 participants