Skip to content

#749 Add support for a @PreDestroy method on a factory, alternative to @Bean(destroyMethod) #756

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

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

rbygrave
Copy link
Contributor

@rbygrave rbygrave commented Jan 6, 2025

Example:

@Factory
final class MyFactory {

  @Bean
  MyComponent myComponent() {
   ...
  }

  @PreDestroy(priority = 3000)
  void destroyMyComponent(MyComponent bean) {
    ...
  }
  • ONLY valid on factory components
  • An alternative to @bean(destroyMethod)
  • The @PreDestroy method matches to a @bean by type only (ignores qualifiers, only 1 argument to the destroy method)

…@bean(destroyMethod)

Example:
```
@factory
final class MyFactory {

  @bean
  MyComponent myComponent() {
   ...
  }

  @PreDestroy(priority = 3000)
  void destroyMyComponent(MyComponent bean) {
    ...
  }
```

- ONLY valid on factory components
- An alternative to @bean(destroyMethod)
- The @PreDestroy method matches to a @bean by type only (ignores qualifiers, only 1 argument to the destroy method)
@SentryMan
Copy link
Collaborator

While technically I see nothing wrong, I'm not a fan of being able to have multiple @PreDestroy methods in a single class.

@rbygrave
Copy link
Contributor Author

rbygrave commented Jan 7, 2025

I'm not a fan of ...

Yes, it isn't perfect per se. I'm comfortable enough that it is intuitive enough and that we've limited this feature enough that it won't become a future regret. Time will tell.

@rbygrave rbygrave added this to the 11.1 milestone Jan 7, 2025
@rbygrave rbygrave added the enhancement New feature or request label Jan 7, 2025
@rbygrave rbygrave merged commit 7b349ea into master Jan 7, 2025
13 checks passed
@rbygrave rbygrave deleted the feature/factory-destroy-method branch January 7, 2025 01:45
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
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Allow factory beans to have a @PreDestroy method to match/mirror a @Bean method
2 participants