Java EE 6 与 Spring 3 堆栈
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2499323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java EE 6 vs. Spring 3 stack
提问by Piotr Gwiazda
I'm starting a new project now. I have to choose technologies. I need something light, so no EJB or Seam. On the other hand I need JPA (Hibernate or alternative) and JSF with IceFaces.
我现在开始一个新项目。我必须选择技术。我需要一些简单的东西,所以没有 EJB 或 Seam。另一方面,我需要带有 IceFaces 的 JPA(Hibernate 或替代)和 JSF。
Do you think that such a stack on Spring 3 deployed on Tomcat is a good choice? Or a Java EE 6 web application could be better? I'm afraid that Java EE 6 is a new technology, not well documented yet. Tomcat seems to be easier to maintain than Glassfish 3.
你认为在 Tomcat 上部署 Spring 3 上的这样一个堆栈是一个不错的选择吗?或者 Java EE 6 Web 应用程序会更好吗?恐怕 Java EE 6 是一项新技术,尚未得到很好的记录。Tomcat 似乎比 Glassfish 3 更容易维护。
What's your opinion? Do you have any experiences?
你怎么看?你有什么经验吗?
回答by Bozho
It doesn't matter. Java EE 6 is good enough and because of the profiles there, it is not "heavy" - you'll just be using the web profile.
没关系。Java EE 6 已经足够好了,而且由于那里的配置文件,它并不“繁重”——您将只使用 Web 配置文件。
Personally, I prefer Spring. But I'm running out of rational arguments against Java EE 6 :)
就我个人而言,我更喜欢春天。但是我对 Java EE 6 的理性争论已经用完了 :)
(As I was reminded by a comment - you might want to try RichFaces, as well as ICEfacesand/or PrimeFaces- depending on what components you need).
(正如我被评论提醒的那样 - 你可能想尝试RichFaces,以及ICEfaces和/或PrimeFaces- 取决于你需要什么组件)。
回答by duffymo
I'd still prefer Spring.
我还是更喜欢春天。
And I'd pass on JSF. I think it's a dead technology. Spring MVC would be a better alternative. So would Flex. Think in terms of contract first XML services and you can decouple the back end from the UI completely.
我会通过 JSF。我认为这是一种死技术。Spring MVC 将是一个更好的选择。Flex 也是如此。从契约优先的 XML 服务的角度考虑,您可以将后端与 UI 完全分离。
回答by Adisesha
Read Adam Bien's Future Of Enterprise Java ...Is Clear (Java EE with/without Spring and Vice Versa), including comments to get both sides of coin. I will choose Spring for several reasons and following is one of them (reproducing one of the comments from post)
阅读 Adam Bien 的企业 Java的未来……清晰(Java EE 有/没有 Spring 和 Vice Versa),包括获得两面性的评论。我会选择 Spring 有几个原因,以下是其中之一(复制帖子中的评论之一)
'I am not sure which Java EE 6 server you are talking about. There is Glassfish certified and TMAX JEUS. It will take quite a while (read: years) until Java EE 6 compliant versions of WebSphere, WebLogic, JBoss etc are in production and can be used for real application. Spring 3 just needs Java 1.5 and J2EE 1.4 so can readily be used in almost all environments'
'我不确定你说的是哪个 Java EE 6 服务器。有 Glassfish 认证和 TMAX JEUS。在 WebSphere、WebLogic、JBoss 等的 Java EE 6 兼容版本投入生产并可以用于实际应用程序之前,还需要相当长的时间(阅读:数年)。Spring 3 只需要 Java 1.5 和 J2EE 1.4,因此几乎可以在所有环境中使用”
回答by Pascal Thivent
I need something light, so no EJB or Seam.
我需要一些简单的东西,所以没有 EJB 或 Seam。
Would you care to explain what makes EJBs heavy since EJB3? Do you realize that we are not in 2004 anymore? I'd really like to read yourdefinition of light and your arguments (and I will update my answer with pleasure because I'm pretty sure I would have a few solid things to say).
您愿意解释一下是什么让 EJB 自 EJB3 以来变得沉重吗?您是否意识到我们不再是 2004 年了?我真的很想阅读你对光的定义和你的论点(我会很高兴地更新我的答案,因为我很确定我会有一些可靠的话要说)。
On the other hand I need JPA (Hibernate or alternative) and JSF with IceFaces.
另一方面,我需要带有 IceFaces 的 JPA(Hibernate 或替代)和 JSF。
Java EE 6 Web Profile which includes JSF 2.0, JPA 2.0, Bean Validation, EJB 3.1 Lite, CDI,... would be perfect for this and you can use GlassFish v3 Web Profileto run an application built with the Java EE 6 Web Profile.
Java EE 6 Web Profile,其中包括 JSF 2.0、JPA 2.0、Bean Validation、EJB 3.1 Lite、CDI 等,非常适合此应用,您可以使用GlassFish v3 Web Profile运行使用 Java EE 6 Web Profile 构建的应用程序.
Do you think that such stack on Spring 3 deployed on Tomcat is a good choice? Or a Java EE 6 web application could be better?
您认为部署在 Tomcat 上的 Spring 3 上的这种堆栈是一个不错的选择吗?或者 Java EE 6 Web 应用程序会更好吗?
Well, Ilike the idea to run my code on a non-proprietary platform(Java EE) rather than on a proprietary container(Spring). And I think that Java EE 6 is good enough (and this is an euphemism, EJB 3.1 (Lite), JPA 2.0, JSF 2.0, CDI kick ass). Note that I was a JSF skeptic but I took a second look and JSF 2.0 with CDI is so different that I can't even compare. And if you didn't look at CDI, let me tell you that it rocks.
好吧,我喜欢在非专有平台(Java EE) 而不是专有容器(Spring)上运行我的代码的想法。而且我认为 Java EE 6 已经足够好了(这是委婉的说法,EJB 3.1 (Lite)、JPA 2.0、JSF 2.0、CDI 踢屁股)。请注意,我对 JSF 持怀疑态度,但我又看了一眼,发现带有 CDI 的 JSF 2.0 是如此不同,我什至无法进行比较。如果你不看 CDI,让我告诉你它很酷。
I'm afraid that Java EE 6 is a new technology, not well documented yet.
恐怕 Java EE 6 是一项新技术,尚未得到很好的记录。
Java EE looks pretty well documented to me. This sounds like free claim. And, believe me or not, Istart to find Spring getting complicated while Java EE getting easier.
Java EE 对我来说似乎有很好的文档记录。这听起来像是免费索赔。而且,不管你信不信,我开始发现 Spring 越来越复杂,而 Java EE 越来越容易。
Tomcat seems to be easier to maintain than Glassfish 3.
Tomcat 似乎比 Glassfish 3 更容易维护。
Did you try something? Did you face any particular problem? Again, this sounds like free claim.
你尝试过什么吗?你遇到过什么特别的问题吗?同样,这听起来像是免费索赔。
回答by Raz
The answer to your questions depends on your project requirements. If you don't require the Java EE features like message queues, container managed global transactions etc then go with tomcat+spring.
您的问题的答案取决于您的项目要求。如果您不需要消息队列、容器管理的全局事务等 Java EE 功能,请使用 tomcat+spring。
Also from experience I have found that projects that require a lot of web service integration, scheduling, message queues are best best done using some of the Java EE stack. The good thing is using spring you can still integrate with Java EE modules running in an application server.
同样根据经验,我发现需要大量 Web 服务集成、调度、消息队列的项目最好使用一些 Java EE 堆栈来完成。好消息是使用 spring 您仍然可以与在应用程序服务器中运行的 Java EE 模块集成。
Java EE 6 is very different from the previous releases, and it really makes everything lot easier. Java EE 6 combines the best ideas from the diverse Java community - for instance Rod Johnson from Spring framework was actively involved in the making of the Dependency Injection JSR in Java EE 6. A benefit of using Java EE 6 is that you are coding according to a standard, which could be important in some organizations for vendor support etc.
Java EE 6 与之前的版本有很大不同,它确实让一切变得更加容易。Java EE 6 结合了来自不同 Java 社区的最佳想法 - 例如来自 Spring 框架的 Rod Johnson 积极参与了 Java EE 6 中依赖注入 JSR 的制作。使用 Java EE 6 的一个好处是您可以根据标准,这在某些组织中对于供应商支持等可能很重要。
GlassFish v3 supports Java EE 6 and it is quite light-weight and starts up really fast. I have been using glassfish v3 for my developments, and it is really easy to configure. It comes with a very user-friendly admin console that lets you graphically administer your server.
GlassFish v3 支持 Java EE 6,它非常轻量级并且启动速度非常快。我一直在使用 glassfish v3 进行开发,而且配置起来非常简单。它带有一个非常用户友好的管理控制台,可让您以图形方式管理您的服务器。
If you are using GlassfishV3 and JSF 2, then you can take advantage of the CDI features of Java EE 6, that lets you easily create conversations (e.g. wizard like pages) in JSF.
如果您使用的是 GlassfishV3 和 JSF 2,那么您可以利用 Java EE 6 的 CDI 特性,这使您可以在 JSF 中轻松创建对话(例如,向导式页面)。
Having said that, using Java EE 6 also requires you to learn a new API. Depending on the timeframe available it might not be the best choice for you. Tomcat has been around for ages, and the tomcat+spring combination has been adopted by many web projects, which means lots of documentation/forums are around.
话虽如此,使用 Java EE 6 还需要您学习新的 API。根据可用的时间范围,它可能不是您的最佳选择。Tomcat 已经存在了很长时间,tomcat+spring 的组合已经被许多 web 项目采用,这意味着大量的文档/论坛存在。
回答by Raz
I'd recommend Spring + Tomcat unless you can wait the time for glassfish v3 and Weld to become more mature. There are currently a few issues with memory consumption/cpu load when running glassfish with CDI enabled applications.
我建议使用 Spring + Tomcat,除非您可以等待 glassfish v3 和 Weld 变得更加成熟。在使用启用 CDI 的应用程序运行 glassfish 时,当前存在一些内存消耗/cpu 负载问题。
回答by bassem
I recommended to you Tomcat with Spring because:
我向您推荐带有 Spring 的 Tomcat,因为:
- Spring can create backing beans for JSP
- You will use Spring to persist object through JPA
- Spring 可以为 JSP 创建支持 bean
- 您将使用 Spring 通过 JPA 来持久化对象
It is good choice to choose Tomcat because you don't need any heavyweight processing
选择Tomcat是不错的选择,因为你不需要任何重量级的处理
回答by Thorbj?rn Ravn Andersen
My opinion is based on something not mentioned by others, namely that code at my work tend to live for decades (literaly), and hence that maintenance is very important to us. Maintenance of our own code, and the libraries we use. Our own code we control, but it is in our interest that the libraries we use, are maintained by othersin the above mentioned decades or more.
我的观点是基于其他人没有提到的,即我工作中的代码往往可以存活几十年(字面意思),因此维护对我们来说非常重要。维护我们自己的代码和我们使用的库。我们控制自己的代码,但我们使用的库由其他人在上述几十年或更长时间内维护,这符合我们的利益。
To make a long story short, I have concluded that the best way to achieve this is by using open source implementations of Sun specifications all the way down to the raw JVM.
长话短说,我得出的结论是,实现这一目标的最佳方法是使用 Sun 规范的开源实现,一直到原始 JVM。
Of the open source implementations Apache Jakarta has proven to maintain their libraries, and recently Sun has done a lot of work in producing high quality implementations for Glassfish v3. In any case, we also have the source for all modules, so if all else fails, we can maintain them ourselves.
在开源实现中,Apache Jakarta 已经证明可以维护他们的库,最近 Sun 在为 Glassfish v3 生成高质量实现方面做了很多工作。无论如何,我们也有所有模块的源代码,所以如果所有其他方法都失败了,我们可以自己维护它们。
Sun specifications are usually very strict meaning that implementations conforming to the spec can be interchanged easily. Just have a look at servlet containers.
Sun 规范通常非常严格,这意味着符合规范的实现可以轻松互换。只需看看 servlet 容器。
In this particular case, I would suggest having a look at JavaServer Faces simply because it is part of Java EE 6 meaning it will be available and maintained for a very, very long time. Then we have chosen to augment with MyFaces Tomahawk as it gives some useful additions, and it is a jakarta project.
在这种特殊情况下,我建议查看 JavaServer Faces,因为它是 Java EE 6 的一部分,这意味着它将在很长一段时间内可用并维护。然后我们选择使用 MyFaces Tomahawk 进行扩充,因为它提供了一些有用的补充,这是一个雅加达项目。
There is nothing wrong with JBoss Seam or others. It is just that their focus is less towards the maintenance issue that is so important to us.
JBoss Seam 或其他没有任何问题。只是他们的注意力不集中在对我们如此重要的维护问题上。
回答by Sebastien Lorber
Didn't read everything but just to tell that you can now use EJB3 inside a war on Java EE 6 so you can use EJB3 on Tomcat (I think).
没有阅读所有内容,只是告诉您现在可以在 Java EE 6 的战争中使用 EJB3,因此您可以在 Tomcat 上使用 EJB3(我认为)。
回答by nash
Why is there still rumblings about EJB being heavyweight in 2010? It seems people are not being updated in Java EE technologies. Just try it out , you will be pleasantly surprised how things are simplified in Java EE 6.
为什么在 2010 年仍然有关于 EJB 是重量级的传言?似乎人们没有更新 Java EE 技术。只要尝试一下,您就会惊喜地发现 Java EE 6 中的事情是如何简化的。