如何设置 Java EE6 应用程序结构
因此,在阅读了 DDD 及其所有好处和荣耀之后,Java EE 似乎并不能让您轻松做到这一点。我的想法是制作这样的结构:
Domain
存储库
应用
然而
,在这个答案的评论中DDD和应用程序层似乎是应用程序 层,我认为将成为所有用 @Stateful、@WebService 等注释的服务的层,但这并不是它真正应该位于的位置。域模型似乎应该具有这些注释。
所以现在的问题是:人们如何构建他们的应用程序?您将不同的注释放在哪里以及它们如何相互使用。有人可以帮助我了解如何构建 java ee 6 Web 应用程序吗?请帮助并说明我如何在特定工具或类似工具中执行此操作,而是说明实际类的位置以及不同层的用途。
我对从哪里开始以及如何组织感到沮丧。
So after reading about DDD and all it benefits and glory it seems like Java EE does not make it easy for you to do so. What I thought was to make a structure like this:
Domain
Repository
Application
View
However in the comment of this answer DDD and application layer it seems like the Application layer which I thought was going to be the layer with all the services annotated with @Stateful, @WebService etc is not the place it really should be in. It seems like the domain models should have these annotations.
So now the question is: How do people structure their applications? Where do you put the different annotations and how do they use each other. Could somebody please help me understand how I can structure an java ee 6 web application? Please help and say not how I do it in a specific tool or anything like that but where the actual classes goes and what the different layers are intended to do.
I am frustrated on where to start and how to organize.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于如何构建您的应用程序,没有具体的规则。最好是运用常识并观察其他人是如何做的。
您可以生成一个由焊接团队提供的简单 Maven 项目,以了解如何构建基本的 Java EE 应用程序:
当然,您会在 github 或 java.net 上找到许多其他示例
There are no specific rules on how you should structure your application. Best would be to use common sense as well as observe how others are doing it.
You can generate a simple maven project provided by weld team to see how a basic Java EE application can be structured:
For sure you will find many other examples on github or java.net
这是一个可能有用的示例 -> EAR 测试
它被称为“EAR 测试”,但也可以像轻松应用于构建战争文件。为了这个答案的目的,我将示例中提到的
eartesting
目录更改为wartesting
EAR 文件和 WAR 文件几乎相同,因为在 Java EE 规范级别我们决定允许
war
文件包含 EJB、CDI bean 等。该示例使用 Maven 构建系统并具有两个模块,一个用于“数据对象”,一个用于“业务逻辑”。似乎符合您的想法,并且可能是一个有用的起点。它包含一个小型示例应用程序,其中包含 EJB 的单元测试。
您可能还没有读过,但人们经常认为 EJB 难以测试。现在已经没有了,该示例显示了最新的符合规范的解决方案,因此您可以从该设置开始用一块石头杀死几只鸟。
其中不包括用于创建将在生产中部署的最终 WAR 文件的模块。要创建它,您只需
在
business-war
中 d 有一个如下所示的 pom.xml:然后创建以下目录:
我们会说例如你添加每个以下文件:
构建后,您应该在
wartesting/business-war/target/
下获得一个 war 文件,其中包含:WEB-INF/web.xml
WEB-INF/classes/org/superbiz/Foo.class
WEB-INF/lib/business-model-1.1-SNAPSHOT.jar
index.html
Here's an example that might be helpful -> EAR Testing
It's called "EAR Testing", but can just as easily apply to building war files. For purposes of this answer I'll change the
eartesting
directory mentioned in the example towartesting
EAR files and WAR files are nearly identical since at the Java EE spec level we decided to allow
war
files to contain EJBs, CDI beans, and more.That example uses the Maven build system and has two modules, one for the "data obects" and one for "business logic". Seems to fit with how you think of thinks and might be a helpful starting point. It contains a tiny sample application with unit tests for the EJBs.
You might not have read yet, but often people refer to EJBs as hard to test. There're not anymore and that example shows the latest spec compliant solution, so you can kill a few birds with one stone starting from that setup.
What that doesn't include is a module to create the final WAR file that you would deploy in production. To create that you'd just add a third module
In the
busines-war
you'd have apom.xml
like the following:Then create the following directories:
And we'll say for example you add the following files to each:
Once built, you should get a war file under
wartesting/business-war/target/
containing:WEB-INF/web.xml
WEB-INF/classes/org/superbiz/Foo.class
WEB-INF/lib/business-model-1.1-SNAPSHOT.jar
index.html