Why I will use Java EE instead of Spring in new Enterprise Java Projects in 2012
javacodegeeks.com
javacodegeeks.com
While the argument itself is worthy of discussion, there was no need to package it inside an article full of fluff.
The author claims that she hopes to be neutral, but completely fails to do so when it comes to comparison of Spring and JEE: she lists advantages of JEE and then those of Spring, but makes sure that each of the Spring advantages listed is accompanied by a "BUT", which boils down to either "JEE has it too" or "JEE doesn't have it, but you probably won't need it".
Yes, I know she said beforehand that she would explain why differences between Spring and JEE lead her to JEE, but the way she did it robs her of neutrality she claims to have. And it's not just the form I'm talking about, it's the substance, too. If all of your reasons to lean towards JEE boil down to "well, it has all that I need that Spring has and I personally don't care about the stuff it doesn't have", you're not really contributing anything.
For example scala programmers completely ignore backwards compatibility problems they have had in the past. Such a thing would unimaginable for a large app.
One is someone who uses tools to accomplish their goals, the other is someone defined by their tools.
1) Spring Portlet MVC - cause we have to deal with Portlet (don't ask)
2) JAX-RS client-side - Portlet talks to GlassFish via JAX-RS
3) JAX-RS server-side - GlassFish RESTful (this is probably one of the key feature for using JavaEE 6, a simple, straightforward, productive way to create APIs that can return XML or JSON or ATOM or ALL of them easily via annotation). JAX-RS is very similar to Sinatra.
4) JAX-WS client-side - to communicate with 3rd-party systems
5) JAX-WS server-side - to provide services for 3rd-party systems
6) Spring-Data - to reduce writing boilerplate JPA 2.x code (the way Spring Data works is as simple as writing an interface method where the method has the same name to the NamedQuery and Spring will automagically inject bytecode)
7) Spring library to read properties file - no need to write the actual implementation of a class that reads a property file and deal with IO exception abd opening/closing files try-catch-finally. Provide an interface and annotate the interface, set up minimal config and you're done.
8) Apache Derby to test the persistence layer for integration testing
9) Spring Web Test module - this provides HTTP Request/Response mock object so you don't have to construct your own
Other libraries:
10) FlyWay - database migration library that integrates nicely with Spring as well. Flyway is executed when you deploy your EAR/WAR to your App Server container.
11) GSON - Java to JSON object converter written by someone from Google. We send JSON from our Portlet MVC to the front-end that is of a mix between JSP (5-10%) and heavy JS usage.
12) Dozer - Object to Object mapping, very useful if you have to deal with 3rd-party systems that have a subset or superset of your internal/local domain model.
13) Maven - we can build for multiple environment (DEV, UAT, PROD, STAGE, etc), it's easy.
We are quite satisfied with the set-up and I have to say that if you come from Rails background, the only part of the stack that would make you a bit unhappy is the database ORM since ActiveRecord is probably nicer compare to the JPA 2.x/Hibernate/Spring-Data.
We're not using EJB yet but we may use it in the future if we have to use queue via JMS as well. To my knowledge the latest EJB (3.1) helps you a lot to deal with transactional multi-steps operations that include persistence operations and JMS operations on one execution path.
I'd say the code that we have to write is almost as short as Rails when it comes to the business logic part.
Deployment was straight forward: package it up as WAR (or EAR) and deploy it to GlassFish.
The part that we're lacking right now is the front-end. Even though we're not using JS _that_ heavy, we are moving toward that direction and eventually we have to clean it up and start using best-practices (Backbone.js, Underscore.js, and a few other things).
First of all, JSF is the most horrible framework for creating web applications that I've ever used. Its intention is to make web development easier, but what you get is a huge mess of HTML and JavaScript that introduces a lot of new problems. Escpecially since it gives you the impression that you don't need to know HTML and JavaScript to work with it.
EJBs are a lot easier, and as long as you don't access them remotely, you don't need interfaces or XML files. If you put them remotely, you need both. With injection you don't need to look up EJBs manually, except if you put them remotely - because if the reference to the remote EJB is invalidated (i.e. if it's accessed while the remote server is down), you'll need to look it up manually again.
As long as you choose something other than JSF, JEE 6 is fine.
Of course, then there's the application servers. I've only tried Glassfish (for a while it was the only fully certified JEE 6 app server), but it had a few problems - I heard one of the latest versions had a GZip filter that would have spinning threads taking 100% CPU.
JEE has come a long way, but I'll probably choose Spring for my next Java project.
- Sustainability - do we really think Spring is going to die?
- Light weight testing is possible - so JEE has caught up with spring...
- Convention over configuration - like spring.
- Multiple providers - OK that's a potential benefit but I'm not seeing the realisation of it yet. It could also mean that different providers have different bugs.
From my personal investigations Spring offers many advantages. In some places JEE has matched them in others it's still behind. So I would ask myself do I want to go with the framework that's driving the advancement, or the framework that is playing catchup? Also these days Spring is the standard.
I've gone back to Servlets+Guice+Velocity because it's easier for me to write expressive code.
I like it's Scala support and enthusiasm though, and I will definitely try it some day again.
Basically, what enterprise features am I missing out on by not using one of them?
Java play is the get it done platform.
They both have their uses.
Java EE 6 is a great skill to have, job wise, but it is more fun using agile platforms.
This article is devoid of any dev value