EJB 3.1或Spring 3 ..何时选择哪一个? [英] EJB 3.1 or Spring 3.. When to choose which one?

查看:115
本文介绍了EJB 3.1或Spring 3 ..何时选择哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EJB在3.x版本中实现了许多改进,Spring也是常用的,而版本3是一个不错的选择。

EJB achieved many improvements in 3.x versions, Spring is also commonly used and version 3 is a good alternative.

关于ejb3x和spring3x的精确比较..你有什么想法,在现实世界的例子哪一个更好的条件?

There are many articles on web, but no exact comparison about ejb3x versus spring3x.. Do you have any ideas about them, in real world examples which one is better at which conditions?

例如,我们想分离db和server,这意味着我们的应用程序将在一个服务器上,我们的数据库将在另一个服务器中.. EJB remoting vs Cluster4Spring etc?

For example, we want to separate db and server, which means our application will be on a server, our database will be in another server.. EJB remoting vs Cluster4Spring etc ?

做每一个@Annotation总是好?

Doing everyting @Annotation is always good? configuration never needed?


推荐答案

对于应用程序在一个服务器上运行且数据库在另一个服务器上运行的用例, EJB和Spring是无关紧要的。每个平台都支持这一点,无论是Java SE应用程序,简单的Servlet容器,如Tomcat或Jetty,PHP,Ruby on Rails等。

You don't need any kind of explicit remoting for that. You just define a datasource, provide the URL where your DB server lives and that's it.

任何种类的显式远程处理。你只需要定义一个数据源,提供你的数据库服务器所在的URL,就是这样。

That said, both EJB and Spring Beans do make it easier to work with datasources. They both help you defining a datasource, injecting it in beans and managing transactions associated with them.

其中,EJB(通常是Java EE)更坚持约定优于配置原则。 Spring需要更多的冗余来获得相同的东西,并且很大程度上依赖于XML文件,这可能很快变得非常大和笨重。硬币的另一面是,Spring可以更少的神奇,你可能会感觉更多的控制后,你想要的一切你的拼写。

Of the two, EJB (and Java EE in general) is more lightweight and adheres more to the convention over configuration principle. Spring requires more verbosity to get the same things and depends a lot on XML files which can quickly become very big and unwieldy. The flip side of the coin is that Spring can be less magical and you might feel more in control after having everything you want spelled out.

另一个问题是EJB和Spring是开发的。

Another issue is the way EJB and Spring are developed.

EJB是免费的(如免费啤酒),开源和非专有。有非营利组织(Apache),开源公司(Redhat / JBoss)和深度商业化封闭源企业(IBM)实现EJB。我个人会避免后者,但是对每个他自己。

EJB is free (as in free beer), open-source and non-proprietary. There are implementations of EJB being made by non profit organizations (Apache), open source companies (Redhat/JBoss) and deeply commercial closed source enterprises (IBM). I personally would avoid the latter, but to each his own.

Spring另一方面是免费和开源,但强烈专有。只有一个公司使Spring,这是Springsource。如果你不同意Rod,那么你会遇到困难的运气。这不一定是坏事,但你可能想知道的差异。

Spring on the other hand is free and open-source, but strongly proprietary. There is only one company making Spring and that's Springsource. If you don't agree with Rod, then tough luck for you. This is not necessarily a bad thing, but a difference you might want to be aware of.


做任何@Annotation总是好吗?

Doing everyting @Annotation is always good? configuration never needed?

这是一个无休止的辩论。有人认为XML很难维护,其他人则认为注释污染了一个纯粹的POJO模型。

It's an endless debate really. Some argue that XML is hard to maintain, others argue that annotations pollute an otherwise pure POJO model.

我认为将一个bean注释为一个EJB无状态bean(@Stateless )或JPA实体(@Entity)使用注释更干净。对于@EJB或@Inject依赖项注入也是如此。另一方面,我喜欢JPQL命名查询在XML文件而不是注释,以及注入表示纯配置数据(如一个最大值的东西)也是在XML中。

I think that annotating a bean as being an EJB stateless bean (@Stateless) or a JPA entity (@Entity) is more cleanly done using annotations. Same goes for the @EJB or @Inject dependency injections. On the other hand, I prefer JPQL named queries to be in XML files instead of annotations, and injections that represent pure configuration data (like a max value for something) to be in XML as well.

在Java EE中,每个注释也可以在XML中指定。如果注释和XML等效项都存在,则XML将覆盖注释。这使得它非常方便地从默认情况下的注释开始,但以后通过XML重写一个特定的用例。

In Java EE, every annotation can also be specified in XML. If both the annotation and the XML equivalent are present, the XML overrules the annotation. This makes it really convenient to start with an annotation for the default case, but override it later via XML for a specific use case.

Java EE中的当前首选项似乎(简单)注释与大量的配置约定相结合。

The current preference in Java EE seems to be more towards (simple) annotations combined with a large amount of convention over configuration.

这篇关于EJB 3.1或Spring 3 ..何时选择哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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