开发者

why do we always put Hibernate, Spring and Strut in one app?

开发者 https://www.devze.com 2023-03-27 07:25 出处:网络
Definitely, I\'m talking about working with MVC pattern. Definitely, Hibernate make our life easier with Model layer.

Definitely, I'm talking about working with MVC pattern.

Definitely, Hibernate make our life easier with Model layer.

But, Spring and Strut both work with Controller and View.
So, my question is: "I cant understand why other guy always put both Spring & Strut in one application while we need just one of them (Strut or Spring). If anyone understand that, p开发者_开发技巧lease tell me, thanks!"

I'm just a kid in Java world, so any comments are appreciated.


But, Spring and Strut both work with Controller and View.

Spring is many things, as you can see in this diagram:

why do we always put Hibernate, Spring and Strut in one app?

One of these things is the Spring MVC framework. I agree, it does not (usually) make sense to use Spring MVC together with Struts (although in large sites, different departments may have different requirements).

However, Spring is also many other things, most of all an IOC framework, and as such it makes perfect sense to integrate different model and view technologies.


Spring is both Spring - the IOC container and Spring MVC - the web action framework. Struts is only a web action framework. So if you prefer Struts over Spring MVC, but also want an IOC container, you will use Struts with Spring.

Additionally, Spring also provides declarative transaction management, a security framework, a set of JDBC helper classes, etc., that you might want to use in a Struts/Hibernate application.


I wouldn't say always. Personally, I have never put Spring and Struts together in the same application, and I am willing to bet that most Spring/Hibernate projects also do not also use Struts.


Spring isn't just MVC. It has much more integrations, such as database, security, DI etc. Usually you want to use one of that features if you use Spring (which doesn't also mean, that you have to use Spring MVC).


Lets say that Spring and Struts are both frameworks that do overlap in some aspects. Even if I think that, if you are utilizing spring to its full extent, there should be no need for struts at all. But people tend to stick with the stuff they are used to. As Struts has been around for quite some time there are a lot of applications based on this and a lot of people that have made a profession out of this and would never commit throwing that away. That's why I have seen quite a lot of these hybrid application around.


I think you misunderstand MVC Pattern in first place. Model is not about persistence, but about the business logic in first place. It usually involves some persistences and service classes. For this purpose, many people choose Hibernate for persistence and Spring IoC for dependency injection purpose.

For the View and Controller part of web application, a well known web mvc framework is Struts and Spring MVC. Spring itself is consists of many components, Spring IoC and Spring MVC is two of them. Spring MVC is an equivalent with Struts so you don't use them together. But it is ok to combine Struts and Spring IoC.


Struts - usually provides MVC framework (most of Production support & maintenance applications are already integrated with it). Spring - to inject/ add new componenets without disturbing the existing java classes/ code.


IT mostly depends on your project requirement, in our project we have used JQuery there are lots of Struts tags are used at the UI Layer and that is the main reason we are using struts2 because struts2 is having very good integration with JQuery Struts2-JQuery Tag Library is very useful hence we are using Struts2 + Spring framework provides an easy way to manage the dependency. (because of its DI and IoC) It can be easily integrated with struts 2 framework. The ContextLoaderListener class is used to communicate spring application with struts 2.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号