Skip to content

Tag: autowired

Autowired property is null in EnvironmentPostProcessor implementation class on startup

In my SpringBoot app, I have Autowired an configObject in the class that implements EnvironmentPostProcessor. The injected class reads data from a different source on startup as this is required for the app to work. But upon starting the application, the configObject is coming off as Null. And the AppEnvironmentPostProcessor class where the Autowired object is called. This class is

Spring Boot Error @Autowired RestTemplateBuilder with junit

Trying to @Autowired a RestTemplate in Spring Boot 2.1.4 using RestTemplateBuilder. When i run junit tests i get an error when trying to autowired RestTemplate. I saw here: How to autowire RestTemplate using annotations It seems that RestTemplateBuilder is better so i would like to use that. This is the configuration file : This is the test class: The error

How to mock a autowired list of Spring beans?

I’ve read plenty of articles about how to mock Spring’s bean and their autowired fields. But there is nothing I could find about autowired lists of beans. Concrete problem I’ve a class called FormValidatorManager. This class loop through several validators which implements IFormValidator. I would like to test this class. But I can’t find a way to mock validators property.