This is an anti pattern, but I am curious what will actually happen.
If you explicitly define a no-args constructor and a constructor with an autowired parameter, how exactly will spring framework initialize it?
@Service
class Clazz {
private MyBean myBean;
public Clazz(){}
@Autowired
public Clazz(MyBean myBean){
this.myBean = myBean;
}
}
The constructor marked by
@Autowiredwill be used by spring. You can validate this by running the following code.The code prints
non-empty.