Search code examples
javaspringspring-mvcarchitectureinversion-of-control

Is this a good Spring Architecture (include testing)


I'm currently working on a Spring project. I made a diagram to illustrate what i'm saying. Is the diagram UML below represent a correct/good architecture to follow with Spring ?

To explain, the RestController redirects requests. This controller have an interface dependancy injected with the real class (here a class that handle storage of reports with files).

The class DatabaseFile implements DatabaseInterface. On one hand, some methods for content treatment ( like getContentFromReport(string) -> call readFile(String) then for instance take only important lines), on the other hand pure file method (like ReadFile using (Reader, FileUtil...)).

My problem is that file methods (readFile(), deleteFolder()) doesn't contain dependancy Injection and I can't mock some objects.

The diagram :

diagram


Solution

  • You must follow the standard MVC approach(view will be the response in JSON/XML). You must keep all you business logic inside DAO layer and inject DAO inside the service layer and then inject this service into the rest controller. For the testing purpose you can mock the dao and service layer.