EJB3 or "Spring3 + hibernate" which one suitable
There are so many things are common in in EJB3 and Spring 3 with 开发者_JS百科hibernate. I need to findout where I can use Spring framework with hibernate not EJB3 and viceversa.
You can use them interchangeably.
If you go with EJB3, you'll have to have a full Java EE, EJB3 app server. Some are free, some are not.
If you go with Spring 3, you need to have the Spring JARs in your CLASSPATH, but a full Java EE app server is not required. Tomcat or Jetty are sufficient, depending on your needs.
There are multiple vendors for EJB3 implementations; after all, EJB3 is merely a specification. There's only one vendor for Spring.
Personally, I prefer Spring. I've used it for six years, since version 1.0, with great success. It's a very high quality framework. EJB3 took a great deal from the lessons learned by Spring and Hibernate. I think Spring's aspect-oriented programming is better than what has been added to EJB3. The other modules (e.g. security, LDAP, web services, etc.) are excellent.
They are both rather similar. See this question as well: EJB 3.1 or Spring 3.. When to choose which one?
If you go with EJB, you can choose to target Java EE. This means that you don't have to include any extra jars in your WAR, since the target environment already supports EJB. Compare this with targeting Java SE, where you don't have to include classes like ArrayList and HashMap in your jar, since any Java SE runtime already has those.
Of course, you can also include EJB jars with your application, which is convenient should you want to target servlet containers likes Tomcat or Jetty. In that case OpenEJB is probably the best choice, but any EJB implementation can run its container in embedded mode (this is a requirement of the EJB spec) and is usable in Java SE.
There's also a version of EJB that's even more lightweight than the full EJB. This is called EJB3-lite and is supported by servers like Glassfish Web Profile and Resin. These are both barely larger than a bare Tomcat (Resin is 23MB) and give you a complete stack out of the box.
I personally think EJB3 is better than Spring. It's less complex and less heavyweight. EJB3 started a revolution with only requiring simple annotations and adhering strongly to convention over configuration. Spring historically required massive amounts of XML for even the most simplest of things. Spring however learned from EJB and is now adopting the same approach.
At the end of the day, both are mature and good technologies though and you can't go wrong with either of them (just avoid mixing them, unless you absolutely have to).
精彩评论