使用 spring 在应用程序服务器中实现业务逻辑

发布于 2024-09-02 17:04:38 字数 268 浏览 4 评论 0原文

是否可以使用 pojo 而不是 EJB 或 Servlet 在远程应用程序服务器中实现业务逻辑???。主要思想是应用 3 层模型,其中客户端可以是 Web 浏览器和桌面应用程序,并且它们共享应用程序服务器中的业务逻辑。

这将是架构

浏览器----->Web服务器-------->|应用程序服务器(业务逻辑通用)|------->|RDBMS通用|
桌面应用程序(例如Swing)->|应用程序服务器(业务逻辑通用)|------->|RDBMS通用|

Is posible implement the business logic in an App Server remote using pojos instead of either EJB or Servlets???. The main idea is apply a model of 3 layers where the clients may be both web browsers and desktop applications, and they share the business logic in an App Server.

this would be the architecture

browser----- >Web Server -------->|App Server(Business Logic common)|------->|RDBMS common|
desktop App(Swing for example)->|App Server(Business Logic common)|------->|RDBMS common|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩起发的微风 2024-09-09 17:04:38

您可以使用 Spring 代替 EJB。我推荐它!

但这两种替代方案都将以出色的方式为您处理事务处理和安全性等企业功能。

无论是否使用 Spring,您的网页仍然需要一个 Servlet 容器。如果正确配置Servlet容器的web.xml文件,Servlet容器就可以启动Spring容器。

使用 Spring 的事务处理示例:

@Transactional
public void execute(..) {..}

以及使用 EJB 3.x:

@TransactionAttribute
public void execute(..) {..}

如您所见,两种替代方案都允许您以声明方式添加企业功能。

阅读 HenryOS 的评论后更新:

可以将所有业务逻辑放在一台服务器上。

一种解决方案是在客户端(WEB 服务器和胖 Swing 客户端)之间使用 Web 服务。这是一个非常好的且松散耦合的解决方案。

如果您需要更快的速度,可以考虑使用 Google 的 Protocol Buffer 或相反,类似的技术。

有趣的是,使用 Web Services 或 Protocol Buffer,您仍然需要在服务器上具有业务逻辑的 Web 容器(例如 Tomcat 或 Jetty),因为它必须为客户端提供 Web 服务。所有 Web 服务框架(例如 Spring WS、CXF 和 Apache Axis 2)都使用 Servlet。

当谈到层时,我建议在 WEB 服务器上使用两层,因为您只需在将数据发送到业务服务器之前呈现和检索数据。在业务服务器上我会推荐三层。顶层处理 Web 服务,中间是业务层,底层是针对数据库和其他企业系统的集成层。

最后,如果您将 CXF 或 Spring WS 与 JAXB 一起使用,那么业务服务器上的所有类都可以编写为 POJO!它也适用于其他几个编写良好的 Web 服务框架。

我希望这能回答您的问题!

You can use Spring instead of EJBs. And I recommend it!

But both alternatives will handle enterprise features such as transaction handling and security for you in an excellent way.

Using Spring or not, you still need a Servlet container for your web pages. The Servlet container can start the Spring container if you configure the Servlet container's web.xml file correct.

A transaction handling example with Spring:

@Transactional
public void execute(..) {..}

And with EJB 3.x:

@TransactionAttribute
public void execute(..) {..}

As you see, both alternatives offers you to add enterprise features declaratively.

Updated after reading HenryOS's comment:

It's possible to have all the business logic on one server.

One solution can be to use Web Services between the clients (WEB server and the fat Swing clients). It's a quite nice and loosely coupled solution.

If you need more speed, you can consider using Google's Protocol Buffer or similar technology instead.

An interesting thing is that with Web Services or Protocol Buffer, you still need a web container like Tomcat or Jetty on the server with business logic, since it must provide the web services for the clients. All Web Services frameworks like Spring WS, CXF and Apache Axis 2 uses a Servlet.

When it comes to layers, I will recommend two layers on the WEB server, since you only present and retrieve data before sending it to the business server. On the business server I will recommend three layers. The top layer to handle Web Services, business layer in the middle and an integration layer against the database and other enterprise systems at the bottom.

Finally, if you're using CXF or Spring WS together with JAXB, then all your classes on the business server can be written as POJOs! It applies to several other well written Web Service frameworks as well.

I hope this answers your question!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文