Autowired class is null in the constructor
I have the following code structure where I am getting null for Autowired Foo class in class Bar. Tried created object of Foo in Bar but then @Autowired Doo becomes null.
@Service
public class Doo{
public String getString(){
return "String";
}
}
@RestController
@Component
@RequestMapping(value = "/do/something", method = RequestMethod.GET)
public class Foo {
@Autowired
private Doo doo;
// method
public String getString(){
return doo.getString();
}
}
@Component
public final class Bar {
@Autowired
Foo foo;
private static final Bar bar = new Bar();
private Bar (){
foo.getString();
}
public static Bar getInstance(){
return bar;
}
}