I would like a @Autowiredclass with a non-empty constructor. Only the following can be cited as an example: this does not have to be a view / service. There may be any component you like with a custom constructor:
@Component
class MyViewService {
private List<String> companies companies;
private MyObject obj;
public MyViewService(List<String> companies, MyObject obj) {
this.companies = companies;
this.obj = obj;
}
}
Of course I can’t just write
@Autowired
private MyViewService viewService;
since I would like to use a list constructor. But how?
Are there any better approaches than refactoring these constructors to setters? I would not like this approach, because ideally the constructor forces other classes to provide all the objects that are needed in the service. If I use setters, I can easily forget to set certain objects.