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!
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).
"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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With