spring framework role in mvc - java

It's a question about Spring Framework and its architecture. I have read a lot about Spring in the middle-tier or in the layer scheme. But, I need to know which is the role of this framework inside the MVC pattern.
I must clarify I'm not talking about Spring MVC, but about the entire framework.
For example:
View: JSP, JSF, etc...
Controller: Servlets, Spring?, etc...
Model: Spring?, Hibernate, JPA, etc...
I donĀ“t know where can I locate this framework.

If you use Spring Framework (context, core, aop, tx, jdbc) for inversion of control, transactions, aspect oriented programming, JDBC support you definitely use it in M.
If you use Spring MVC for your web controllers you definitely use it in C.
If you use Spring jsp tags, you also use it in your V.

Below url would be helpful to you.
http://www.tutorialspoint.com/spring/spring_overview.htm

Related

JSF and Container Support

Since JSF managed beans are not part of a bean container, who manage them for example like Spring beans. Also how managed bean achieve the dependency injection with out a bean container?
How JSF would be a better replacement for Spring with out a bean managed container and with other functions Spring provides?
JSF is basically an MVC framework focused in the view layer. When comparing it with Spring, it could be an equivalent to Spring MVC, but never to the whole Spring framework, which has much more functions.
For your question of who manages the dependency injection, the own JSF framework used to do that, for me, as an example, I'm using Tomcat which is just a servlet container, so I use JSF for that work (this means I can only inject other managed beans and not a Service or a DAO).
In other cases, for JavaEE servers as JBoss or Glassfish, the server itself has an embeded container (which acts like the Spring framework) so you could delegate the injection to its CDI implementation.
Finally you tell about JSF being an Spring replacement. As I've said before, this makes no sense. JSF is a part of JavaEE specification and it's being oriented to be used with CDI injections. Spring MVC, being part of the Spring framework, could be the best choice if you manage your application with Spring instead of with a JavaEE container, although you could also use JSF instead of it.
Anyway, remember there's always the discussion of going with Spring or JavaEE. The first one, being a non-standard, offers a faster support and improvement releasing. On the other hand, JavaEE follows the Java specification, with all the benefits of that.
See also:
Spring 3.0 vs Java EE 6.0
Using JSF as view technology of Spring MVC

how to create mvc based application without using framework

Struts, Spring and a few other frameworks implement the MVC architecture to separate the representation of information from the user's interaction with it.
Can any one explain or give me a link for that in Java EE?
Without using a framework, how can I create an MVC application and what are the design patterns needed for that?
Take a look at this presentation, which is part of Beginning & Intermediate Servlet & JSP Tutorials on http://www.coreservlets.com/
you can use Servlet and Jsp to create a MVC application without using any framework,
here are some useful links,
http://forum.codecall.net/topic/72183-mvc-application-in-java/
another useful example,
http://css.dzone.com/articles/web-mvc-java
I think this is a good tutorial on Creating MVC architecture with servlets and jsp
The main concern in creating MVC architecture is the separation of concerns. You need to separate business layer, presentation layer and controler layer
Model layer is achieved by simple POJO
View layer i.e. Presentation layer can be achieved by JSP
Controllers can be achieved by servlets in java ee
MVC stands for Model View and Controller. It is a design pattern that separates the business logic, presentation logic and data.
Controller acts as an interface between View and Model. Controller intercepts all the requests.
Model represents the state of the application i.e. data.
View represents the presentaion.
This link contains an example to implement it with JSP and Servelet.
You can use Servlets and JSP directly.
For managing Java EE applications we are using design patterns.
MVC-1 and MVC-2 are design patterns for managing the UI layer.
Struts and Spring-MVC are implementations of the MVC-2 design pattern.
To answer you first question: the part of the Java EE framework that implements MVC is called JSF. This provides templates, graphical components (widgets) and much more.
To answer your second question: you don't really build an MVC app without any framework. You may be using Servlets and JSP, but that too is a framework. Java EE in its entirety is a (full stack) framework as well.
As for the third question: this is simple, the design pattern to use for MVC is MVC.

How to apply MVC concept in Spring (non-web application)

I like the concept of MVC, and Spring provides one, called Spring MVC. However it looks like it targets on web application.
If I want to use MVC concept in Spring environment, how to do that?
MVC has nothing to do with Spring; it is a software design architecture/design pattern that you can apply to separate out disparate parts of a software codebase (Model, View and Controller). So long as you implement all your business logic in your model, your GUI logic in your view and your controller responds to any events occuring on your view and updating the view as necessary based on the model then you're adhering to the MVC pattern.
This article shows how MVC would be implemented in a Swing environment. Spring MVC can only ever be used as a web framework. The Spring Framework itself however can still be used wherever you want as it is not tied to a Servlet-based architecture (IoC container).
Once you get to grips with MVC another design pattern/architecture, which is closely related to MVC called MVP (Model View Presenter) is interesting, although very similar, seems to me to be a valid successor to MVC as it completely dumbs down the GUI side.
It is a bit more high level, but you may want to look at Spring RCP project.

Struts + Spring + Hibernate integration

For example, we have the next bunch: Struts, Spring, Hibernate. Can you help me understand the role played by each of the elements?
I know that Hibernate is responsible for all on the database.
But, what role Struts and Spring in this case?
Thanks.
Struts is web application framework - used to give you the possibility to expose your application through web interface without dealing with low level classes. When using struts you should be careful as there often bad advices on using you application logic inside struts classes. Don't do this, struts is just web front-end.
Spring is general application framework that in first place helps you decouple classes from one another using dependency injection. But this is not the only reason for using spring, it provides tons of other features: http security, aspect oriented programming, out-of-the-box integrations and support of different frameworks. So this gives you a fast start on using different technologies.
Hibernate is object relational mapping. Using it you map your classes to database relations and avoid working with SQL requests.
My guess:
Struts is used for presentation purposes. Spring is used for AOP, and Depency Injection. Hibernate is obvious: persistence.
Spring:
Dependancy injection
Transaction Management.
Open Session in View Filters
Spring Security.
or in other words nice clue to between application layers.
Struts:
Model and view Design pattern.
Simplifies web flow.
Struts is for webapplication preparation. It has great form validation f/w, and tiles f/w to create webapplication in a great way.
Spring has 6 modules. It provides abstraction on the java-j2ee application. Spring MVC provides abstraction for struts.

Spring MVC vs JSF [duplicate]

This question already has an answer here:
Difference between Request MVC and Component MVC [closed]
(1 answer)
Closed 6 years ago.
I haved used Struts framework in all my past applications and for the new application,my client has requested to use either Spring MVC or JSF? I am not familiar with these two frameworks but our timelines are strict. So, I am not sure which framework I will choose to build the application.
Can anyone please suggest me which framework will be easy to learn in quick time?
Thanks
Of course, it's going to be different for everyone, but I'd suggest Spring MVC, as it's a request-based framework like Struts. Of course, you'll want to learn about core Spring stuff like Inversion of Control / Dependency Injection (but I'd consider that a plus...) and whatever you're going to use for database access (just JDBC? Hibernate? iBatis? etc.).
JSF is component-based, which is a bit different paradigm from request-based frameworks. If you do plan to go the JSF route, I'd suggest looking at Seam from JBoss. It's more of a front-to-back framework that uses JSF as the web/presentation end and EJB as the backend. And pretty much all the people who've used it claim it makes JSF and EJB more usable than they are by themselves.
Good luck on whichever technology you choose, though. (Sounds like you'll need it - strict timelines and a client that's prescribing web frameworks?)
I'd suggest SpringMVC, because of the timeframe:
you need something with less steep learning curve. SpringMVC is more like Struts than JSF
in order to use the power of JSF you need to get familiar with many "tricks", while SpringMVC is more or less straightforward
I'd suggest JSF + Primefaces component library. I am using this combination to build most of our projects. As I remember, I spent one week to learn the technology and finished my first project in one month. The development time at least 30% faster than Struts.
SpringMVC is not a bad technology and it's quite popular.
Really depends on which one your like the most.
JSF is just the view layer of the MVC and wil need to be used with other technologies like Spring/Hibernate or EJB for a full MVC.
I have been using the Spring MVC for about 1 months now, whilst it's probably not the latyest version of SpringMVC I've found it a little annoying that we have so much XML to deal with. All the managed beans and DAO has XML config to it. Also everything seems to have to go thorugh a method called onSubmit().
JSF with something like EJB is far simplier in my opinion... Everything can be done using Annotations so simply use #ManagedBean=theBean in your backing bean and in your JSF put {thebean.param} and you have access to the backing bean's data. Also you can use the Session beans of your EJB as the backing beans for JSF then have direct acces to the DAO (Model layer) Entity bean. Again simply by using the #Entity annotation and the EntityManager class
Spring MVC is a web framework inside the Spring framework. It does provide features as those in JSF 2.0:
ajax-support
validation
dependency-injection etc
Yet, you can use Spring (not Spring MVC) together with JSF 2.0, with spring providing the dependency-injection, aop, transaction management mechanisms, and JSF providing the web layer.
Of course, you'll want to learn about core Spring stuff like Inversion of Control / Dependency Injection (but I'd consider that a plus...)
JSF is indeed based on IoC, and much simpler than the Spring learning curve.

Categories

Resources