- What is the purpose of interface
Short answer: dependency injection
Long answer: You see, we do not want concrete implementation and strong coupling in our application. Interfaces serves that purpose, with or without Spring. Spring is a framework that heavily leverages on that. With an interface, you can write multiple implementations of a single logic by defining a contract (interface methods) that describes what is the parameter and return types but you did not specify how is it done. Which gives you a lot of flexibility in writing different Spring beans (Impl classes) that do that. List
in Java is an interface, then you have implementations like LinkedList
and ArrayList
- How should Spring MVC project be structured
Short answer: anyway you like
Long answer: Are you using Spring MVC as API server or serving views like JSP/Thymeleaf? If I am writing an API I would have Controllers (entry point and spring specific features), Facades (business logic that is pure Java without framework classes), and DAO/Services (depending if data comes from database or 3rd party API, maybe both) at bare minimum. For MVC I would have almost similar setups but depending on your agreement with your API provider I might scrap the service layer and focuses more on the Javascript side. In this day and age I'd advise against using JSP/Freemarker. They are a lot slower to develop compared to having let's say React + API server in any language.