Affects: spring-framework 5.3.29
simplify code:
@Bean
// @LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
// the first way using annotation @Resource inject value to field
@Resource
@LoadBalanced
RestTemplate restTemplate;
// second way using annotation @Autowired inject value to field
@Autowired
@LoadBalanced
RestTemplate restTemplate;
the second way when starting an application-context will throw an exception that bean not found but the first way will start successfully.
It seem like @Resource
not filter by @LoadBalanced
annotation.
Comment From: snicoll
If you want support, please avoid sharing code snippet in text like that with an incomplete stacktrace. It makes it really hard for us to help as we have to figure out the missing bits.
@Resource
has by-name semantic and @Autowired
has by-type semantic. In the first case you may have a bean named restTemplate
. Please review the documentation and, if you still think you've found a bug, attach a small sample that we can run ourselves and we can reconsider.