EJB3 与 Spring

发布于 2024-09-03 12:56:00 字数 246 浏览 11 评论 0原文

我了解到,如果我在 Spring 上下文中使用 EJB,我将获得与在“纯”EJB3 环境中使用它相同的好处,这是真的吗?我用谷歌搜索过,但找不到明确、明确的答案。

例如,假设我有一个会话 bean,它更新数据库中的某些表,并且它抛出系统异常。在“纯”EJB3 环境中,事务会回滚。例如,如果我使用 Spring @Autowire 这个 bean,Spring 是否以与 EJB3 容器相同的方式处理事务处理?或者什么?它可能需要一些特定的配置还是完全“自动”?

I have understood that if I use EJB in Spring context, I get all the same benefits as if I was using it in "pure" EJB3 environment, is this true? I have googled but can't find a definitive, clear answer.

For example, let's say I have a session bean that updates some tables in the database and it throws a System Exception. In "pure" EJB3 environment the transaction is rolled back. What if I for example @Autowire this bean using Spring, does Spring take care of the transaction handling same way as does the EJB3 container? Or what? Does it maybe require some specific configuration or is it fully "automatic"?

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

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

发布评论

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

评论(4

巾帼英雄 2024-09-10 12:56:00

我明白如果我在中使用EJB
Spring上下文,我得到的都是一样的
好处就像我在使用它一样
“纯粹的”EJB3环境,这是真的吗?

您通常使用 POJO + Spring 或 EJB3。我对“Spring 中的 EJB”的含义有点困惑...

POJO + Spring 和 EJB3 现在非常接近,并且在声明式事务管理方面具有相同的设施。

我不知道有关安全性的所有细节,但我想说这两种技术也非常相似。

实际上Spring和EJB3都依赖于其他规范。重要的是:JPA(持久性)、JTA(分布式事务)、JMS(消息传递)、JDBC(数据源)。两个技术堆栈都对此提供了良好的支持。

这两种技术都变得非常灵活,您可以选择使用或不使用什么。因此您可以在应用程序中使用 EJB3。服务器并且非常轻。或者,您可以将 Spring 与所有模块一起使用,这几乎与成熟的应用程序一样重。服务器。

我认为 EJB3 模型仍然更丰富一些,包括远程处理、有状态会话 Bean (SFSB)、容器管理的事务和扩展的持久性上下文等。加上根据应用程序可能支持的集群。服务器。但这些都是很少使用的高级功能(IMO 需要专业知识)。

请参阅EJB3 与 Spring

I have understood that if I use EJB in
Spring context, I get all the same
benefits as if I was using it in
"pure" EJB3 environment, is this true?

You usually use either POJO + Spring or EJB3. I'm a bit confused by what you mean by "EJB in Spring"...

POJO + Spring and EJB3 are quite close now, and have the same facilities when it comes to declarative transaction management.

I don't know all the details about security, but I would say that both technologies are also very similar.

Actually both Spring and EJB3 rely on other specifications. The important ones are: JPA (persistence), JTA (distributed transaction), JMS (messaging), JDBC (data sources). Good support for that exist in the two technology stacks.

Both technologies have become very flexible and you can choose what to use or not. So you can have EJB3 in an app. server and be very light. Or you can use Spring with all modules which is almost as heavy as a full-fledged app. server.

I think the EJB3 model is still a bit richer, with things like remoting, stateful session beans (SFSB), container-managed transactions, and extended persistence context. Plus the possible support of clustering depending on the app. server. But these are advanced features which are use seldom (and IMO require expertise).

See EJB3 vs Spring

意犹 2024-09-10 12:56:00

spring 有很多功能,其中之一是 事务管理,它在所有不同的orm实现(jpa、原始hibernate、jdbc、jdo等)中使用通用抽象。默认行为是,在事务方法中,运行时异常会导致回滚(这可能是您想要的),但您也可以 微调回滚规则

然而,这一切都不需要 EJB。如果您不使用 EJB(无状态、有状态、mdb),JPA 就足够了,并且 spring jpa 支持 非常出色。在 90% 的情况下,Spring 无需 EJB 即可提供您所需的一切。


编辑:

阅读有关 Spring EJB 集成的内容

spring has many features, one of which is transaction management, which uses a common abstraction accross all different orm implementations (jpa, raw hibernate, jdbc, jdo etc). The default behavior is that in a transactional method, a runtime exception causes a rollback (which is probably what you want), but you can also fine-tune the rollback rules.

However, none of this requires EJB. If you don't use EJBs (stateless, stateful, mdbs), JPA will be enough for that, and the spring jpa support is excellent. In 90% of the cases spring will provide everything you need without EJBs.


EDIT:

read this about Spring EJB integration

潇烟暮雨 2024-09-10 12:56:00

您可以让 Spring 处理事务并相应地回滚。您必须对其进行配置才能执行此操作,但 EJB 也是如此。

生活中没有什么是真正“自动”的。有时你必须告诉代码你想要什么。

真正的问题是:为什么您认为同时需要 EJB 和 Spring?您可以使用 EJB 执行的任何操作都可以使用 POJO 和 Spring 来完成。 EJB 在这里为您购买什么?

You can have Spring handle transactions and roll back accordingly. You have to configure it to do so, but that's also true of EJBs.

Nothing in life is truly "automatic". You have to tell the code what you want sometime.

The real question is: Why do you think you need both EJBs and Spring? Anything you can do with EJBs can be done using POJOs with Spring. What are EJBs buying you here?

沒落の蓅哖 2024-09-10 12:56:00

我通过文章链接得到了很好的答案,根据我的理解,会话 bean 的工作方式是相同的,无论它们是否与 Spring 一起使用,只要 bean 是在 Spring 上下文中定义的。还找到了一篇关于此的好、简单的文章:http://java.lang. dzone.com/articles/ejb-30-and-spring-25

然而,我不能只接受一个答案,因为对我来说它们都同样好,但没有一个完全正确:)可能是我的问题不够清楚,无法开始...

(建议我将此作为我自己问题的答案)

I got very good answers with links to articles, and from those I compiled my understanding that yes, the session beans work the same way regardless of if they are used with Spring or without, as long as the beans are defined in the Spring context with <jee:jndi-lookup>. Also found a good, simple article about this: http://java.dzone.com/articles/ejb-30-and-spring-25

However I can't accept just one answer because to me they are all equally good, but none of them exactly in point :) Could be that my question was not clear enough to start with...

(It was suggested that I post this as an answer to my own question)

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