Call controller from another controller -Java

one controller to call a method on the 2nd controller. There are 2 implementations I have seen so far.
1st Implementation
return new Controller().method(request, response);
2nd Implementation
@Autowired
private Controller controller.

return this.controller.method(request, response);
Which is the right implementation, what are the problems if any with either of them.
Ans:
What is the advantage of this? Doing so breaks a lot of convention, and you should be considering revising, i.e. breaking up the controller code and maybe moving some of the logic into the business layer.
--------------------------------------
Ans: 
Sounds like you need to refactor the code. Extract what is common between the two controllers into a separate class, then call that from either controller.
------------------------------------------
Ans:


if you do a call in between controller either there is a flaw or you want to make a redirection which is totally valid. If redirection is the case just return in your controller code as follow.
return "redirect:/yourDestinationControllerPath.htm";

Comments

Popular posts from this blog

EJB - Stateful vs Stateless

Mirror binay tree - Java