Is it better to use spring mvc with hibernate? - java

I am going to develop small ERP System. The product has only one major requirement to support multiple databases.
I have planned to use
Front side: JSP+JSTL+JQuery [I have good command on that] + I have create my own custom component for re-useability and full control of my component.
Back-end: Using hibernate[ORM] framework [due to Cross database] and I have also good knowledge of it.
I am happy with above and feeling confident to build product, soon.
BUT
My friend made me unhappy ;)
My friend suggest me that you should use spring MVC with hibernate, because when your product become large,it create a problem in future due to many developers involvement.So, you should use framework , so that every developer follow the pattern and then your product remain stable.
But I am already follow hibernate pattern :)
I have no any knowledge of Spring MVC. When I search about spring MVC , I found it is a different thing than my requirement and also find Cross database context issue, if I use Spring MVC with hibernate.
Either should I used spring MVC or not. If yes, I have to learn then Spring MVC and
I do not want to waste my time, if spring is not suitable for me.
That's why I am consulting that forum , to go for right direction.

Actually, Spring MVC does not interfere with any of the components you have chosen already. It just introduces a way to structure your frontend - backend interface in a standard way (MVC pattern).
I actually run the very same setup and is very happy with it. (Jquery, JSP, Spring MVC, Hibernate).
Other than structure, you will get easy return of invested time in Spring MVC when you want to do Ajax heavy things (as I assume you want in an ERP app). It's trivial to build AJAX/JSON stuff with jQuery and SpringMVC.

Using Spring MVC will make your application structured. This will help in future maintenance.
Your code will look clean and you can separate your code into components and Spring will help you wire them together and you might decide to combine them in different ways, or wish to make it easy to swap out one component for another depending on different settings or environments. This would be great for multiple databases when used with hibernate.
Learning spring will not take much time if you have a good knowledge of Java EE.

Related

Java Spring Boot Hibernate, JPA, MVC, REST confusion

I'm learning Java SE and Spring Boot for a half year now, and watched different courses, and they teaching different ways, and I'm just confused which one does what?
In one course, we're using Eclipse, Spring MVC and Hibernate with MySQL, and writing everything like Servlet, Hibernate configure file, factory, session, and it's just a bit complicated how to do a query for example. In the other course, we're using Spring Initializr, Maven, REST API with PostgreSQL, and it's so much easier, we implementing CRUD repository, and just one line, we can do the query.
And I'm lost at this point. These what I just mention, what exactly we use them for? Why we don't use the simple way in the first course? What we done in the second that I don't have to create a factory and a session to do a simple query?
Is there any post, video or anything about this, for me to understand it?
There are always different ways to solve the same problem. Spring Boot offers you a lot of features to simplify your development. But you don't have to use them. You can always try to implement stuff by yourself. But most of the time, the built in features like the CRUD repository are sufficient to solve your problem.
I can't tell you the exact reasons, why the author of the first course did it this way. Maybe he or she wanted to show the principles, that are hidden beneath the features. Maybe it is just an older course or it is for Spring and not Spring Boot. Spring Boot simplified the setup for Spring and made many advancements.
Spring Framework has been there for a really long time, the ways you have seen are both valid ways, and as far as I understood by your statements is, one way is working with Spring MVC and the second is working with spring boot and spring boot makes things really easy.
You need to understand the difference between the spring MVC framework and spring-boot.
In spring MVC Framework we manage things with configuration files, like XML files and we also fire queries by opening a session first, and then only we can query. But in Spring-boot these things happens behind the scene and that is why it becomes so easy to work with spring-boot but anyhow we still need to understand all this stuff to be able to work properly with this framework.
Spring MVC is a complete HTTP-oriented MVC framework managed by the Spring Framework and based in Servlets. It would be equivalent to JSF in the JavaEE stack. The most popular elements in it are classes annotated with #Controller, where you implement methods you can access using different HTTP requests. It has an equivalent #RestController to implement REST-based APIs.
Spring boot is a utility for setting up applications quickly, offering an out-of-the-box configuration in order to build Spring-powered applications. As you may know, Spring integrates a wide range of different modules under its umbrella, as spring-core, spring-data, spring-web (which includes Spring MVC, by the way), and so on. With this tool, you can tell Spring how many of them to use and you'll get a fast setup for them (you are allowed to change it by yourself later on).
Spring boot is just an auto-configuration tool. Spring MVC is a web framework
Spring boot = Spring MVC + Auto Configuration(Don't need to write xml file for configurations) + Server(You can have embedded server).
Java EE, Spring and Springboot are not the same.
Spring is based on Java EE.
Spring boot is an 'extension' of Spring, especially with auto-configuration.
There are multiple frameworks or libraries which comes with its own advantage and disadvantages, however you need to choose the TechStack that suits your particular application's requirements.
So if you need to build a web app you can use Java Servlet ,but you have to handles multiple concerns yourself and it involves lot of configuration , but there are many frameworks like Spring,Struts,etc which makes the take easy
Similar way you can manually manage dependencies or you can use Maven or gradle to handle the dependencies and building process
Similar way if you need to connect to a Database you can directly use JDBC but there ar multiple ORM(Object Relational Mappers) available which will make the task easier like Hibernate, Jooq, etc
Regarding your question there is Spring framework and also SpringBoot , main motto of Springboot is that it prefers "conventions over configuration" meaning you only need to write very little code to get started and it comes with many starter-packs which basically are pretty much preconfigured, so you can build application easily
Different frameworks and libraries comes with its own learning curve but they reduce the time required for configuration and troubleshooting
Read about Spring MVC and Spring-boot framework. What you have mentioned is first is spring mvc and other is spring boot framework. make you understanding with the questions like, what problem spring boot solves ?? that was or is there in spring mvc.
JPA: The Java Persistence API (JPA) is one possible approach to ORM. Via JPA the developer can map, store, update and retrieve data from relational databases to Java objects and vice versa.
Hibernate: Hibernate is an open-source object-relational mapping(ORM) tool for Java. It provides a framework for mapping an object-oriented domain model to a traditional relational database.
MVC: The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components: the model, the view, and the controller.
JAVA: One of the most widely used programming languages, Java is used as the server-side language for most back-end development projects, including those involving big data and Android development.
Springboot: Spring Boot is an open-source micro-framework. Spring Boot helps developers create applications that just run. Springboot is a JAVA framework.
REST: Representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services.

CRUD Spring-Boot with ZK?

I want to make a web-based application using spring-boot with zk as backend and frontend, but I still haven't found a good tutorial.
Spring boot itself is a convention based framework to setup/configure an application(-server). It has examples for many ways to load/store data, each with their own tutorials, so you have to at least choose the persistence technology most suitable for your scenario ... be it spring data, jdbc, restful or nosql or webservice based ... you name it. Then someone might be able to point you to a dedicated tutorial.
From the ZK perspective all that doesn't really matter. Being a front end framework it doesn't make any persistence assumptions. I.e. you can load/save data from/to any source in your controller/viewmodel code (delegating to your spring-services / repositories). Here an example project, demonstrating how a spring service can be wired and used inside MainViewModel.
Now it's up to you to decide and implement what the spring service will do, when its methods are called. For your CRUD scenario you'll most likely need methods to create, read, update and delete your data objects.
E.g. Spring data provides standard interfaces for that e.g. CrudRepository
Before you decide to use spring-data you should definitely read and understand the common concepts first. After that the integration into spring-boot should feel less mystical (we've all been there), and you can pick the options you want, instead of a tutorial someone put together - most likely under different assumptions unsuitable to your situation.
I suppose that you have fundamental skills in Java and in web development. If you do, but you are starting with spring boot I recommend starting with spring boot by reading articles in baeldung.com and mkyong.com for specific things.
To get a general perspective of spring boot I recommend that you read the book "spring boot in action" by Craig Walls:
You can purchase it online or find it in here.

Architectural Differences in Java MVC Web Frameworks

I'm trying to choose an AJAX-friendly Java framework for my first web application and am interested in first
understanding the architectural differences between the different flavors that are out there.
I like the concept of MVC frameworks, and so am primarily considering the following:
Any JSF variety (ICEFaces, RichFaces, PrimeFaces, etc.)
Spring Web Flow
ZK
Wicket
I've downloaded each of these projects and tried to follow their samples/tutorials, and there is
so much information to ingest I figured I'd take a breather and come here to cover some preliminaries
first.
I'm interested in how each of these frameworks implements the MVC pattern. Obviously, something rooted
in JSF (like ICEFaces) is going to have a different architecture than Spring. I'm sure that this is a
huge question, so I'm not looking for a full-blown tutorial on each of these frameworks; I'm just
curious as to what sort of artifacts (Java sources, XML config files, etc.) a developer has to write in
order to build a single AJAX-driven page using these. I'm interested in the differences to their approach,
nothing more.
For instance, I would imagine that each framework at some point uses a FrontController (or its likes) to
map HttpRequests to the right Controller implementation. That Controller (bean) would then need to do
some processing, possibly hit the database for some information (using ormapping and forming the Model), and
then construct a View/HttpResponse to send back to the client. This is an oversimplification I'm sure, but
there has to be an easy way to explain the high-level architecture for how each of these frameworks accomplishes
that.
Struts uses the ActionServlet (with Struts2 now its just Action) as the controller and model and jsp is the view.
For Spring MVC is achieved by DispatcherServlet which does the routing and Model is not bound to any framework related object you can use any.
JSF - UI jsp or jsf itself, Model - ManagedBean, Controller - FacesServlet.
I did some similar search for my own project a while ago, have a look at the links below:
Comparison based on multiple parameters : http://static.raibledesigns.com/repository/presentations/ComparingJavaWebFrameworks.pdf
Difference between JSF and Struts
http://struts.apache.org/2.0.14/docs/what-are-the-fundamental-differences-between-struts-and-jsf.html
Somewhat related post
https://stackoverflow.com/questions/7633583/which-mvc-is-better-spring-or-struts
Spring and JSF
http://blog.springsource.org/2007/04/21/what-spring-web-flow-offers-jsf-developers/
Spring MVC : http://static.springsource.org/spring/docs/2.0.x/reference/mvc.html
Best Fit For JSF Component Library: Primefaces based on my own experience
From IBM Clearing the FUD : http://www.ibm.com/developerworks/library/j-jsf1/
Hope this gives you some insight.
Have a look at Matt Raible's talk on Comparing JVM Web Frameworks here. You can also consider looking at Spring MVC and 'Tapestry`.
Also, this link gives you a matrix on capabilities of various java web frameworks.
You should also check out the Play framework. I have used it a little and really like it.
It is very easy to get started with minimal configuration (reminds me of Rails).
http://www.playframework.org/

Spring MVC Struts Mixing

This is really a general question.
I have an ecommerce webapp that I built solo about 4 years ago. At the time, I made the decision to use Struts as my mvc framework. As years passed working on other projects, I came to appreciate and feel much more comfortable with the feature set and flexibility offered by Spring MVC.
The service layer is solid, and is built using the spring framework.
I'd like to refactor my current web layer to now use Spring MVC. But as I have mentioned previously, I wrote the app solo and it's more of a side project. The point being that I do not have time, nor do I want to risk throwing away and completely reengineering the web layer from scratch.
So I'm asking the community on what their strategy would be for this refactoring effort?
Ideally, I would like to tackle pieces at a time, and ultimately mix the two technologies until eventually when I can completely turn off Struts.
All new functionality for my site would best be developed in Spring MVC.
The good thing is that my existing views, which is currently using apache tiles, would not have to change much, with the exception of removing struts tag libraries and replacing them with Spring MVC.
One requirement I'd like to keep is that the URL's should not change.
In other words, the ActionServlet and the DispatcherServlet would have to map to separate paths but somehow go to different implementations.
For example, how can I say that mysite.com/show-product maps to a Spring Dispatcher servlet, but mysite.com/show-category maps to a Struts action servlet.
Your thoughts are appreciated.
You can run them both in the same container with appropriate mapping.
I don't understand the question "should I convert action classes to spring controllers one at a time", how else would you do it?
Whether an action class should map to a method of a controller has more to do with your existing app's organization than anything else, or at least how you want the Spring app organized.
No, you don't need to rewrite your actions. See here:
http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/web-integration.html
Look for "18.4 Apache Struts 1.x and 2.x"

What web frameworks can be used successfully on Google app engine? What about Struts/Spring?

I'm interested in porting an existing application which was written using Spring/Struts2/Hibernate to GAE. I didn't read many successful stories about that so first of all I'm wondering if it is wise to use any of them there. I want to get rid of hibernate and to use the google data store instead since it's obvious hibernate is not a good choice on GAE. So my main questions refers to Struts2(webworks)/Spring. My app uses simple JSP pages, no other template mechanism.
My question refers to the following aspects:
Currently each page has struts actions associated. Each request is taken by struts dispatcher an then it is dispatched to specific action class after which it invokes a specific jsp, according to the config file.
Everything is instantiated by Spring(actions, factories, hibernate layers,...)
The security is managed through a Spring Security(former acegi).
My first impression is that I should get rid of Spring because GAE should manage all the objects in order to work in a distributed environment. I have a few antagonistic thoughts regarding Struts. However, if I get rid of them ,I'm not sure if I should do it and in case I will, what to choose instead. Is GAE good enough to provide all the things I needed? I assume instantiation should be handled by GAE to have a truly sclalable solution. What about session management, security & user privileges? GAE provides good mechanism to manage them behind the scene or I should manually handle them like in a classic jsp solution? Will I end in having a huge web.xml?
Are there any frameworks that fits well in GAE and which can replace Spring/Struts? I would be interested to find out from someone who experienced those problems in GAE.
Here is a list of frameworks which are known to work or to have issues:
http://code.google.com/p/googleappengine/wiki/WillItPlayInJava
In general Hibernate will not work, but you could potentially use Java Persistence instead. Struts should be OK, but Spring Security is not fully compatible while other Spring parts are fine.
As far as I know, Struts is generally a layer over standard Servlet API - so it should be running without many changes. Spring also is not a problem, in fact, on the web there are many blog entries about spring on GAE. Hibernate - yeah, better use JPA.
If you want to rewrite whole app, you can always go with GWT, even with Spring ( GWT/GAE Spring IoC powered )

Categories