Java EE 6 and alternatives [closed]
Asked Answered
L

5

11

I am a Java SE developer but I have rich web-background (PHP, Perl/CGI and so on) and now I am starting new project. It will have web interface, spaghetti business logic, relational database as storage and connections to other services. I do it from the scratch.

My colleagues told me to use spring, spring security and struts. I look briefly at Java EE 6 spec and found that it covers almost all aspects of enterprise application. I asked my colleagues why do they need spring and struts, but looks like they use technologies simply because they are familiar with them and not familiar with classic Java EE 6 stack.

So, my question is: what is bad about Java EE 6? Why do I need spring if there are JNDI lookups? It will take a day or two to create fake InitialContext for unit-tests. And that is all: I stand with out of external tools like spring. Why do I need spring-security if there is a security built in Servlets spec? I can map any request to any servlet using web.xml, no struts.xml is needed. I can use servlet-filters instead of struts interceptors. There is RMI, so I do not need spring-remote. And so on..

Why should I bother my self with all that fancy stuff if there is Java EE 6?

I really want to find situation when Java EE 6 is not enough. Do you have any?

Thanks!

Loud answered 15/1, 2011 at 3:12 Comment(7)
There's quite a huge difference between the vintage J2EE from then and the modern Java EE 6 from now. What one are you talking about? Then, Spring and Struts were great add-ons on top of J2EE. But now, Java EE 6 provides almost the same already out the box. Your colleagues might be still hanging in the ancient ages.Ftc
Sorry) Java EE 6. I am not going to use Java 1.2 )))Loud
Please revise/retag your question then. You might as well reconsider it :) Similar question here and here.Ftc
Done) But my question remains the same: why everybody use alternative technologies but not java enterprise?Loud
You're still talking about "J2EE". As to the why, well, they still need to meet the relatively new Java EE 6.Ftc
ll that people ask about web. But web is just a thin tier. I know how I'll do it. I will use JSP as template engine (I like XSL but it is hard to find anyone who likes it except me and my HTML coder). I will use plain javascript, not GWT (because application is not ajax-centric and all business login will work on server side). I would not probably use JSF because I am not fond of "web-components" after my asp.net projects. Web is clear for me. ... __ What is the difference between java ee 6 and java ee <6 for my question?Loud
JEE6 comes with relatively a lot of changes and new things which are learnt/overtaken from Spring. CDI, annotations, convention-over-configuration, etc.Ftc
A
12

Why people use Spring and why it is so popular requires a little history.

It used to be that Spring was simpler than Java EE applications. I refer to the EJB2.x spec. I get the sense there was sort of a rebellion against the complicated nature of that spec. Developers wanted a simpler architecture, and Spring provided that for them by allowing them to write POJOs (Plain Old Java Objects) instead of classes that had to implement specific interfaces to get the desired functionality.

Spring also made 2 principles more popular: Inversion of Control (IoC) and Dependency Injection. Combined, those two principles provided a different way of wiring up the various components of an application, and getting those components into the application when it ran. That, combined with the idea of just writing POJOs was very compelling for many people, because code was simpler and it was easier to wire up all of you components.

The newer EJB3 spec nullifies some of what Spring has to offer, but Spring is much more than an IoC container. It provides great templates for JDBC access to the database, multiple simple ways of handling transactions, testing utilities, an MVC stack, and so on. It was popular and remains popular. One joke I have heard is

"EJB3, the answer to the question noone asked..."

EJB3 is a fine choice. Spring is a fine choice. Grails is also a fine choice (uses Spring, Hibernate under the covers).

Acinus answered 15/1, 2011 at 3:49 Comment(4)
I am a big fan of Grails! Amazing how fast you can get up and running.Pedo
and I don't. Grails is nice, but as of the version we are using - 1.3.3 - still rather unstable. We had to fix a few bugs ourselves (after reporting them, of course). And they were not some corner-case bugs.Hillhouse
@bozho, yep, I agree that there are issues; its not perfect yet. But in the end, it has allowed me to move faster on many projects.Acinus
I have to dispute the "question no one asked" part. Everyone hated EJB2 and wanted something better... The obvious question was can we get this out of a universal spec? But I upvoted this for being a good, pithy answer.Valaria
G
1

"So, why do I need spring?"

Ilya! Finally you have convinced me (and hopefully yourself) that you do not need Spring. Actually there is nothing much special good in all this heap ... unless you have already are used to it. They write a book about web technology, then add the rest of computer science into it and call that RESTfull.

"However, imagine having lots of code that handles form input and lots of models. Each controller may have a view".

Amir! - very good consideration. The real difference between web frameworks I know is in what a definition of component is. Struts has three types of components - View, Controler and Model components. At first glance looks good (better than some others for sure). But what can you build of those components? - One page View, one Page Controller and one page Model. God knows what will be the cost of binding items from these three rows of components - maybe a huge configuration if at all possible.

The real solution is (as you practically stated in the quoted above) is a concept of components that each has its view, its controller and its model. Only one framework went that far so far - HybridJava. What is a web page building block in Spring?

Gabriel answered 15/1, 2011 at 3:13 Comment(0)
E
1

Spring is not necessary to Java EE. Spring just makes complex Java EE components easy to use.

Edgerton answered 15/1, 2011 at 3:28 Comment(2)
I know it) But I can use JNDI instead of spring DI. So, why do I need spring?Loud
JNDI is in no way comparable to Spring DI. CDI is.Ftc
E
1

Sounds like you need to POC particular capabilities with Spring and then with Java EE 6 so you can compare the two like for like with a real working practical prototype.

The reasons I use spring however, are:

  • ability to abstract my application away from the application server. I can thus run on any application server, or outside of AS for unit testing
  • a lot of the boiler plate code that I would have to write, to improve my design is already available
  • IOC/DI - the object that needs dependencies does not know about how to get them - all it knows is what interfaces it requires. Some third party provides them. Yes, you could roll your own version of this third party in Java EE 6 but it is already available in Spring.
  • Bean Managed Transactions - Spring provides all the tools you need to have complete low level control on your transactions. I would always suggest using BMT as it gives you the flexibility you might need.
Elvera answered 15/1, 2011 at 7:54 Comment(0)
P
0

Spring a model-view-controller that makes Java EE cleaner and more organized. It is structurally more correct to separate your models, views and controller.

I agree with you. If it is a simple website then I think you can do everything with just Java EE. However, imagine having lots of code that handles form input and lots of models. Each controller may have a view. You can create a servlet and then forward to the correct jsp page, or you can use spring because it already does all of this.

The decision is your of how much you need to use spring. A good framework is one that lets you pick and choose what parts to use. I think spring does this well because you can just use the mvc model or go further and do more with it.

Final thing, spring has dependency injection which makes configuration much easier.

Pedo answered 15/1, 2011 at 3:46 Comment(5)
Thanks. I can implement MVC pattern my self: Each servlet is a controller and JSP page is just a view. I would not use any logic inside JSP (because it is impossible to test). I can use JNDI (service lookup) with out for spring. It is as good as dependency injection, is not it?Loud
I think you are trying to reinvent the wheel. Which is cool but why would you do that when Spring has already been tested by millions of users. If you say a learning experience then I am totally with you. Otherwise, you are off just reusing it libs that have been created and tested.Pedo
@Ftc could you elaborate on that? Let's say I have a shopping application. Wouldn't I want one servlet for item lookup, one servlet for order creation, one servlet for customer history, etc?Lemming
@glowcoder, look at existing MVC frameworks like JSF, Spring MVC, Struts, Vaadin, Echo, etc. All use a single servlet as MVC entry point (controller). To get the basic idea, you may find this answer useful: #3541577Ftc
If you really 'get' object oriented programming and think that java based web UI frameworks should support it fully (much like C++ desktop UI frameworks did 20 years ago) then you'll really appreciate the 'component oriented' Wicket UI framework over legacy 'action oriented' style JSP/Struts/Spring MVC UI frameworks.Unilateral

© 2022 - 2024 — McMap. All rights reserved.