4

I am new to JavaEE and Spring Framework. I am having difficulty in understanding how we can write application using Spring Framework only. I have read over the internet that the intention of Spring Framework was to make development of enterprise level application simpler as opposed to EJB development (mainly in EJB 2.x series).

With JavaEE we have many technologies like: 1) EJB 2) JCP 3) JTA 4) JPA and so on.

While reading Spring Framework, i started with Dependency injection, Spring AOP, Spring MVC (and others i am reading).

I have difficulty in understand as to how just using Spring DI / AOP / MVC can it make full-blown Enterprise application? I read from one of the posts that, for example, for transaction management, we can use Spring's own Transaction management or use JTA. I believe JTA is part of JavaEE, and if we eventually use JavaEE's technologies, then how spring eases life?

Any answers which would help me clear this is highly appreciated.

CuriousMind
  • 8,301
  • 22
  • 65
  • 134
  • 1
    See also: http://stackoverflow.com/questions/7295096/what-exactly-is-java-ee – lexicore Oct 25 '14 at 11:54
  • 1
    See also: http://stackoverflow.com/questions/1061717/what-exactly-is-spring-for – lexicore Oct 25 '14 at 11:55
  • http://stackoverflow.com/questions/627839/spring-vs-jboss – lexicore Oct 25 '14 at 11:56
  • Spring was here before J2EE5 and added a lot of simplification in response to the complexity of J2EE4. But now with J2EE5+ EJB3/JPA things are easy even if it's still an heavy beast. – nomoa Oct 25 '14 at 12:01

2 Answers2

9

Spring consists in many different parts, and so does Java EE. Some of them are direct competitors, while for others, Spring provides an abstraction layer and/or Spring integration of Java EE components.

For example:

  • Spring MVC is built on top of servlets (which are part of Java EE), and it competes with JAX-RS and JSF
  • Spring core (IoC, AOP) competes with CDI and EJBs
  • The Spring transaction handling is just an abstraction layer on top of existing transactional mechanisms (JPA, Hibernate, JDBC or JTA)
  • Spring-data-JPA is an abstraction layer on top of JPA
  • Spring-JDBC is an abstraction layer on top of JDBC

So, for a typical webapp built with Spring, you will at least use come components of Java EE: servlets, maybe JDBC or JPA. If you need messaging and XA, you'll use JMS and JTA, but Spring will provide an integration layer. Regarding dependency injection, you won't need EJBs and CDI, because Spring has direct support for the same functionality.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • So nutshell is we need to have knowledge of JavaEE as well, as Spring does use of the technologies of JavaEE. Does it mean Spring can't exist on its own (if it doesn't use JavaEE). The more i study about JavaEE / Spring, the more confusing it becomes whether what i have understood, is the actual way. – CuriousMind Oct 25 '14 at 12:29
  • You need to have knowledge of what you use. Java EE and Spring are extremely large. I use them for years, and there are many parts I don't know about because I don't use them. But yes, if you use Spring MVC, you need to understand how the servlet API works. And if you use the servlet API, you need to understand how HTTP and Java work. It's a pile of layers, and you're never completly isolated from the underlying layers. Similarly, knowing JDBC and SQL is useful (I'd say necessary) if you use JPA. – JB Nizet Oct 25 '14 at 12:39
  • Thanks for your response, appreciate a lot. Then why there is debated that Spring is (or was) replacement of Java EE (when behind the scene Spring uses the technologies which Java EE has to offer?). Like i read some posts as to how to migrate Java EE to Spring Framework? I believe, Spring and Java EE are meant to work hand to hand, not as competitors, is that correct to conclude? – CuriousMind Oct 25 '14 at 12:43
  • 1
    As I said, some parts are in competition, some are not. A whole part of the debate is about marketing and ego. To sell itself, Spring said that EJBs were too difficult and untestable (which was true, BTW), and that Java EE was not moving fast enough. Java EE backers replicated by improving Java EE (CDI, EJB3) and taking many of the good ideas made popular by Spring. All in all, when they are in competition, both have their strengths and weaknesses. – JB Nizet Oct 25 '14 at 12:51
  • Just to point out another difference: JavaEE application servers do not have the same implementations of each spec (for instance, JBoss uses Hibernate as its JPA implementation, while Glassfish uses Eclipselink). So in case you need to change the application server, you should consider if it is neccessary to migrate parts of your code (propietary extensions, XML configuration, etc). The abstraction layers offered by Spring libraries minimize this effort if you migrate from one application server to another. – A. Rodas Oct 25 '14 at 15:16
  • Thanks everyone for sharing your experiences. – CuriousMind Oct 25 '14 at 16:22
1

First of all, define Enterprise application - AFAIK "Enterprise" in Java EE is just a marketing term.

JavaEE is a set of API's and a bunch (a big one) of standards/specifications for building scalable server-side applications in Java, thus allowing to create something big and complex - something that could be called "enterprise".

Spring is an application framework (some would say "THE framework") which integrates with J2EE.

You are a programmer, thus you are the one who makes

full-blown Enterprise application

from a set of components, offered by Java EE, Spring or whatnot.

pdeschain
  • 1,411
  • 12
  • 21
  • Thanks for you response. Does it mean that we need to know technologies which JavaEE has to offer and using Spring Framework, integrate those components? – CuriousMind Oct 25 '14 at 12:02
  • If you are serious about java server-side development, than you need to know JavaEE and popular frameworks (such as Spring), at least on basic level. JB Nizet's answer is just about that. – pdeschain Oct 25 '14 at 12:04