Skip to content

Add public method to get bean order #34712

Open
@mhalbritter

Description

@mhalbritter

Hello,

in Boot we have the use-case to get the order of a bean. We have the bean instance, and also the bean name.

We tried:

return new AnnotationAwareOrderComparator() {
	@Override
	public int getOrder(Object obj) {
		return super.getOrder(obj);
	}
}.getOrder(bean);

but this only looks at the bean itself, not the factory method.

Combined with this:

Order orderAnnotation = beanFactory.findAnnotationOnBean(beanName, Order.class);
if (orderAnnotation != null) {
	return orderAnnotation.value();
}

it also supports @Order on the bean method, but it's missing @Priority (is that supported on bean methods?) and, looking at org.springframework.beans.factory.support.DefaultListableBeanFactory.FactoryAwareOrderSourceProvider there's also a ORDER attribute on the bean definition.

There's also org.springframework.core.annotation.OrderUtils but this only looks at annotations, not at implements Ordered.

Would it be possible to provide a way to reliably get the order of the bean?

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions