spring-cloud / spring-cloud/spring-cloud-commons
@RefreshScope breaks bean order
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 751
- Forks
- 744
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
Describe the bug
When autowiring a list of beans, Order annotation can be used to order this list of beans. If we add the RefreshScope annotation in one of these beans then this bean gets order=Ordered.LOWEST_PRECEDENCE and the list is not ordered anymore.
Sample
Custom Object:
public class CustomObject {
private String name;
public CustomObject(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Spring configuration:
@Configuration
public class BeanConfiguration {
@Bean
//@RefreshScope
@Order(1)
public CustomObject firstBean() {
return new CustomObject("first");
}
@Bean
@Order(2)
public CustomObject secondBean() {
return new CustomObject("second");
}
}
Test:
@SpringBootTest
class DemoApplicationTests {
@Autowired
List<CustomObject> names;
@Test
void testOrder() {
Assertions.assertThat(names.stream().map(CustomObject::getName)).containsExactly("first", "second");
}
}
When @RefreshScope is added at "firstBean" our test fails.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the @RefreshScope annotation and the DemoApplicationTests sample, reproducing the failure with the two CustomObject beans and their @Order values. Trace how refreshed beans participate in autowired List ordering; done means the test still receives "first" followed by "second" when @RefreshScope is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100