I have created RestTemplate Bean in main class and injected this bean in another class of different package by using @Autowired.When I try to use it is null.
Main class: package :com.ff.filter
@ComponentScan(basePackages= {"com.ff"})
@SpringBootApplication
public class CcFilterSearchApplication {
public static void main(String[] args) {
SpringApplication.run(CcFilterSearchApplication.class, args);
}
@Bean
@Primary
RestTemplate restTemplate() {
return new RestTemplate();
}
}
package where I have injected bean :com.ff.filter.friendlist
@Component
public class CustomFriendList {
@Autowired
RestTemplate restTemplate;
@PostConstruct
public void init(){
System.out.println("inti "+restTemplate);
}
public List<String> blockedList(String userId) throws JSONException {
System.out.println("restTemplate "+restTemplate);
}
}
When i call this(blockedList) method restTemplate is printing null.Anyone one please help.