这是一个好的Spring架构(包括测试)吗? [英] Is this a good Spring Architecture (include testing)

查看:56
本文介绍了这是一个好的Spring架构(包括测试)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事Spring项目.我做了一个图表来说明我在说什么.下图UML是否代表Spring遵循的正确/良好架构?

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 ?

为说明起见,RestController重定向请求.该控制器具有注入真实类(此处是处理带有文件的报告存储的类)的接口相关性.

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).

类DatabaseFile实现DatabaseInterface.一方面,一些用于内容处理的方法(例如getContentFromReport(string)->调用readFile(String),然后例如仅占用重要的行),另一方面,是纯文件方法(例如,使用(Reader,FileUtil ...)的ReadFile ).

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...)).

我的问题是文件方法(readFile(),deleteFolder())不包含依赖注入,并且我无法模拟某些对象.

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

该图:

推荐答案

您必须遵循标准的MVC方法(视图将是JSON/XML中的响应). 您必须将所有业务逻辑保留在DAO层中,并将DAO注入服务层中,然后将此服务注入其余的控制器中. 出于测试目的,您可以模拟dao和service层.

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.

这篇关于这是一个好的Spring架构(包括测试)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆