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

Allow functional bean registration to set bean order (equivalent to @Order) #30849

Closed
cloudshiftchris opened this issue Jul 10, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@cloudshiftchris
Copy link

cloudshiftchris commented Jul 10, 2023

Presently there is no equivalent to @Order when using functional bean registration to allow ordering of beans outside of the bean implementation (where @Order, Ordered, PriorityOrdered etc can be used):

    // no attribute for order, no access to BeanDefinition, and BeanDefinition doesn't have an order attribute
    bean<SomeBean>(name = "abc", ...) 
    @Bean
    @Order(33)  // bean ordering set separately from bean implementation
    fun someBean() = SomeBean()

@Order works at sort time (provider.orderedStream() or injecting a List<> of beans) by introspecting the factory method looking for @Order via an implementation of OrderComparator.OrderSourceProvider that uses beanDefinition.getResolvedFactoryMethod() (org.springframework.beans.factory.support.DefaultListableBeanFactory.FactoryAwareOrderSourceProvider).

It would be useful to have order as an optional first-class property on BeanDefinition which would allow the functional bean registration API to (optionally) provide an order and furthermore allow @Order processing to be collapsed to the same mechanism, while also providing future capabilities for any bean registration capability to support bean ordering.

Without this capability there is no mechanism for functional bean registration to provide bean ordering external to the bean implementation, as is possible with @Order.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 10, 2023
@sdeleuze sdeleuze self-assigned this Oct 24, 2023
@sdeleuze sdeleuze added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 24, 2023
@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 20, 2023
@sdeleuze sdeleuze modified the milestones: 6.1.1, 6.1.2 Nov 20, 2023
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Nov 30, 2023
This commit allows to define a bean order programmatically
at bean definition level (functional equivalent of
`@Order`).

If specified, the order attribute defined at bean
definition level overrides potential values set with
`@Order`.

See spring-projectsgh-30849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants