79587722

Date: 2025-04-23 02:19:46
Score: 0.5
Natty:
Report link

I would like to provide more clearance to your case

first as Cranic Cai pointed out that you should annotate you BaseConfig class with @Configuration annotation so that the spring will pickup and instantiate the object and injected it in Spring Context so you can @Autowired it in all other Spring Context object related.

second if you already directly instantiate a new object in the bean definition like this

@Bean
    @Primary
    RestTemplate restTemplate(@Autowired RestTemplateBuilder restTemplateBuilder) {
        return restTemplateBuilder.errorHandler(
new IPSRestErrorHandler() -> this is a new object will not be autowired from Spring Context
).build();
    }
}

it will not be autowired from your defined class component because you instantiate a new object here. if this is what you want then you can remove completely the @Component annotation from IPSRestErrorHandler class

public class IPSRestErrorHandler extends DefaultResponseErrorHandler { ... }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Configuration
  • User mentioned (0): @Autowired
  • User mentioned (0): @Component
  • Low reputation (0.5):
Posted by: Aleson