How JavaEE and Spring are related / unrelated? [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
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.

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.

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.

Related

Is Struts2-Full-Hibernate plugin the standard way to integrate Struts2 and Hibernate? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm starting a project, willing to use Struts2 and Hibernate.
Should I use the struts2-full-hibernate plugin, or integrate them differently ?
Searching on Internet confused me: is it the standard way to integrate them ? If not, which is the standard way ?
In a nutshell:
Choose a framework for the front-end (usually MVC, then Struts2, JSF2, Spring MVC, etc... you've already chosen Struts2. The standard (not necessarily the better nor the most used) in the Java EE 6+ stack is JSF2);
Choose a persistence manager:
the standard with Java EE 6+ is JPA 2.0 (JSR 317 - Java Persistence API). JPA are just annotations, you need a library implementing them; Hibernate can be used as JPA implementation. Hibernate is not the only JPA provider, but it is the most used one (not necessarily the best one), and hence the most standard. With this configuration, you can structure the application's layers by separating the presentation layer (Struts2 actions) from the persistence layer, where the CRUD is performed. The DAO layer is also not needed anymore because JPA's EntityManager is the dao itself.
You can otherwise use raw Hibernate with its proprietary annotations (or any other persistence manager), and in that case, with Struts2, you can use the (vintage?) Struts2-Full-Hibernate plugin. It simplifies some jobs, but force you to use the OSIV (Open-Session-In-View) (anti)pattern.
After having chosen the framework and the persistence manager, you need to chose a DI (Dependency Injection) manager. If you are using Java EE 6+, the standard is to use CDI (JSR 299 - Contexts and Dependency Injection). Before Java EE 6, or for nostalgic developers, Spring is still available. It's been the first library providing DI / IoC (Inversion of Control) when Java EE was lacking it.
Specifically, with Struts2 you can:
integrate CDI with the Struts2-CDI-plugin;
integrate Spring with the Struts2-Spring-plugin.
Conclusion
According to Java EE, the standard configuration with Struts2 (instead of JSF2) is:
Struts2
Java EE 6+ (CDI + JPA 2.x + EJB 3.x)
Hibernate 4.x
Struts2-CDI-plugin

Spring's ORM (hibernate) vs hibernate [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have used hibernate in my java project where I have used Spring MVC.
I avoided SPRING HIBERNATE because it seemed that it was making my code very tightly coupled. Now, even if I move the app to struts, my service layer would work fine (because I have used the core hibernate , it is not the one that spring provides).
I would like some experienced developer to answer this:
What is the reason of using spring hibernate? I know it provides a number of features but there is a trade off as it really makes your code tightly coupled, you can't re-use the services any where else since they would work based on spring's hibernate api
Spring having 7 different modules each are independent you can use anyone of them or multiple
The core container
Spring context
Spring AOP
Spring DAO
Spring ORM
Spring Web module
Spring MVC framework
you want to know about the ORM integration believe me it doesn't make any tight coupling with your service layer
you can use strut mvc at the same time on service layer spring-orm + hibernate there is no tight coupling, more over spring is providing transaction mgt. hibernatetemplate support, you need not to take care of session and transaction mgt and of course easy integration and configuration.
According to my experience Spring-Hibernate provides:
A template to make 'easy' its configuration
The persistence engine can be used as a dependency, so you can change it whenever you want without modify JPA annotations in your model classes
It's supposed to be much more efficient managing XA transactions
And nothing else ...
well complex question, i could answer it with another question :
What is the reason of using hibernate? I know it provides a number of features but there is a trade off as it really makes your code tightly couple, you can't re-use the services any where else since they would work based on hibernate api.
Why not using direct JDBC and SQL ?
To be more productive on the question : choosing a framework always come with a trade off : being coupled with the framework.
So either the features provided by the framework be worth to pay the trade off or not.

Is JSF/JSP the only choice if I use the Java EE to develop my site? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am studying Java EE technology. I noticed that JSF is an available choice for developing web application. But is it the only choice if I wanna use Java EE tech?
You have numerous Choices when it comes to choosing Web Application Frameworks, depending upon your choice you select one.
You can go for no framework too, but it would be like ending up with complex designs that even yourself won't be able to understand later.
JSF, Netty, Seam, Sitemesh, Spark, Spring MVC, Stripes, Struts, VRaptor, Wicket are some of the examples you can go for.
With JSF, you have navigational framework, MVC framework and RichFaces/IceFaces for front-end. With others, you have navigation and mvc too, and you can use jQuery for front-end.
When it comes to using Databases, transactions, etc. You will have to make another choice between persistence implementations i.e. JPA, EJB3.0 JPA Implementation, Hibernate, Spring with Hibernate and MVC and IoC.
so.. long story short, you need to read.
JSF is only one of the Front-End solutions. There are too many to enumerate.
There are differences between they, advantages and disadvantages.
Other Javascript based UI is GWT.
You can have non Javascript based ones: JSP or even just servlet for a "Hello word"
You can use frameworks which will have the MVC pattern embedded: Struts, Spring.
For start learning: I would choose a framework free implementation - to learn what is implemented later in different frameworks. Just a plain JSP pages written manually.
Later on production, bigger J2EE, which will require more team members, higher speed of development, you can choose a framework, which the project needs and most of developers know.

how to make choice between spring framework and EJB3 [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
JEE6 vs. Spring 3 stack
Let I’m going to develop a mission critical application which will be massively transaction based. I will do it with Java. Now I have to choose the technology. My application must be scalable, good performing, code must be maintainable and I want to get long term ROI. First thing, I’m going to choose framework. As a framework, spring comes at first in my mind. But I know there are more like EJB3 or anything. Now my question, what should I choice, EJB3 with JPA or spring framework with Hibernate. I know every technology have tradeoffs. Can anyone help me to make good choice? And one thing to make clear, I’m still learner.And I want to know advantage and disadvantage of EJB and spring framework too. Thanks
And I want to know advantage and disadvantage of EJB and spring
framework too
Both are light and POJO based, and you could get a good picture from similar threads. You might find that many of the pain-points that existed with EJB 2.x are no longer there.
'EJB' might simplify things for you
If your application would need distributed transactions started by remote clients
If your application is message-driven
Now my question, what should I choice, EJB3 with JPA or spring
framework with Hibernate.
Also look at adding CDI to the stack ( i.e EJB3.x + JPA + CDI ) and then compare with (Spring + Hibernate)

Spring vs EJB. Can Spring replace EJB? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Since Spring is able to use transactions just like EJB. For me, Spring is able to replace the requirement of using EJB. Can anyone tell me what are the extra advantages of using EJB?
Spring was developed as an alternative to EJB right from its inception, so the answer is of course you can use Spring in place of EJBs.
If there's an "advantage" to using EJBs, I'd say that it would depend on the skills of your team. If you have no Spring expertise, and lots of EJB experience, then maybe sticking with EJB 3.0 is a good move.
App servers written to support the EJB standard can, in theory, be ported from one compliant Java EE app server to another. But that means staying away from any and all vendor-specific extensions that lock you in to one vendor.
Spring ports easily between app servers (e.g., WebLogic, Tomcat, JBOSS, etc.) because it doesn't depend on them.
However, you are locked into Spring.
Spring encourages good OO design practices (e.g., interfaces, layers, separation of concerns) that benefit any problem they touch, even if you decide to switch to Guice or another DI framework.
Update: This question and answer are five years old in 2014. It needs to be said that the world of programming and application development have changed a great deal in that time.
It's no longer just a choice between Java or C#, Spring or EJBs. With vert.x it's possible to eschew Java EE altogether. You can write highly scalable,
polyglot applications without an app server.
Update: It's Mar 2016 now. Spring Boot offers an even better way to write applications without Java EE app servers. You can create an executable JAR and run it on a JVM.
I wonder if Oracle will continue to support the Java EE spec. Web services have taken over for EJBs. The EJB solution is dead. (Just my opinion.)
First, let me say it clearly, I'm not saying you shouldn't use Spring but, because you are asking for some advantages, here are at least two of them:
EJB 3 is a standard while Spring is not (it's a de facto standard but that's not the same thing) and this won't change in the foreseeable future. Although you can use the Spring framework with any application server, Spring applications are locked into both Spring itself and the specific services you choose to integrate in Spring.
The Spring framework sits on top of the application servers and service libraries. Service integration code (e.g. data access templates) resides in the framework and is exposed to the application developers. In contrast, the EJB 3 framework is integrated into the application server and the service integration code is encapsulated behind an interface. EJB 3 vendors can thus optimize the performance and developer experience by working at the application server level. For example, they can tie the JPA engine closely to JTA transaction management. Another example is clustering support which is transparent to EJB 3 developers.
EJB 3 is not perfect though, it is still lacking some features (e.g. injection of non managed components like simple POJOs).
Pascal's points are valid. There are, however, the following in favour of Spring.
EJB specification is actually a bit loose, and therefore different behaviours can be observed with different application servers. This will not be true for the most cases, of course, but I've had such a problem for some "dark corners".
Spring has a lot of extra goodies, like spring-test, AOP, MVC, JSF integration, etc. EJB has some of those (interceptors, for example), but in my opinion they are not that much developed.
In conclusion, it depends mainly on your exact case.
Spring is meant to complement EJB, not to replace it. Spring is a layer on top of EJB. As we know, coding of EJB is done using API, which means we have to implement everything in APIs using the Spring framework. We can create boiler-plate code, then just take that plate, add some stuff to it, then everything's done. Internally Spring is connected with EJB -- Spring wouldn't exist without EJB.
The main advantage of using Spring is that there is no coupling at all between classes.

Categories

Resources