Spring and Spring MVC -- are they two different framework? - java

As I am trying to learn some framework J2EE, I am studying on spring framework.
The thing that confused me in some tutorial they mention Spring MVC as a part of the spring framework. But at some place they mentioned as like a different and independent framework. some people even compare Spring MVC with Struts (which is another framework as i understand ).
Now how actually should i take Spring MVC in mind as a different framework like Struts or as a part of Spring?

Spring has incredibly grown in the last decade, so nowadays the single word Spring means different things depending on the context in which it is used. In such context might be used the following Spring projects.
One of these projects is the Spring Framework: an open source application framework and inversion of control container for the Java platform which offers lots of features:
Dependency Injection
Aspect-Oriented Programming including Spring's declarative transaction management
Spring MVC web application and RESTful web service framework
Foundational support for JDBC, JPA, JMS
Much more...
each one of these features is designed in a Spring Framework's module grouped in layers, so among others, you can find:
in the core layer
The Core and Beans modules provide the fundamental parts of the framework, including the IoC and Dependency Injection features.
...
...
in the web layer
...
The Web-Servlet module contains Spring' s model-view-controller (MVC) implementation for web applications. Spring's MVC framework provides a clean separation between domain model code and web forms, and integrates with all the other features of the Spring Framework.
...
..
Your question
Now how actually should i take Spring MVC in mind as a different framework like Struts or as a part of Spring?
Both are right because of what summarized above: Spring includes Spring Projects and one of them is Spring Framework which contains Spring's MVC framework.
So if you think the single word Spring both as the most general and as the Spring Framework, Spring MVC is part of Spring.
Moreover you may consider Spring MVC like Struts, because Spring's MVC framework application domain is extremely closed to the Struts one.
I think your confusion comes up from considering a part (Spring's MVC framework) as different from the whole (the most general single word Spring or the Spring Framework) in which the part may be thought included.

Spring in common meaning is framework provided by spring-core artifact [http://mvnrepository.com/artifact/org.springframework/spring-core]. Contains IoC, Dependency Injections and other stuff.
Spring MVC using Spring to bootstrap application context, and add some functionality and features specified to MVC. You should think about Spring MVC as 'plugin' or 'extension' of Spring.

Spring is a Java EE-like stack. The core Spring framework provides Dependency injection, AOP, JDBC helpers etc. Also there are a couple of sub-projects: Spring MVC, Spring batch, Integration etc. (See the full stack here: http://spring.io/projects)
Yes Spring MVC is veri similar to Struts, as both are action oriented MVC frameworks. Usually the sub-projects depend on the core and not on the other sub-projects.
The main point is that Spring is a stack of technologies.

Related

what is the difference between Spring and Spring MVC framework

I am new to Spring. Can any one let me know what is the difference between Spring and Spring MVC Framework ?
Spring is a big framework, that contains a lot of components. One of these components is Spring MVC - it is a component that lets you implement your web application according to the model-view-controller design pattern.
1- Spring in abstract word is a framework
The Spring Framework is an open source application framework and inversion of control container for the Java platform.
Check this links for more information:
Spring Framework
Framework vs. Toolkit vs. Library
2- MVC architecture
it is an architecture that help the developer to separate the building block of web application.
Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications
check this link for more information:
Basic MVC Architecture
MVC is a Spring module. You use it for designing web applications. MVC in Spring implements the front controller design pattern. In your web.xml you'll define a single servlet (DispatcherServlet) and all your requests will pass through it and will be attended by Controllers you will define (#Controller).
Spring is a framework which helps to connect different components together. There are many modules for IOC, AOP, Web MVC etc.Spring Framework is an open source application framework and inversion of control container for the Java platform.
Spring MVC (Model–view–controller) is one component within the whole Spring Framework, to support development of web applications.
Spring MVC is one component within the whole Spring Framework, to support development of web applications. You can use any web containers, so it works fine with Tomcat. Just think that Spring is a third party library. You just need to put the necessary jar files in the lib directory, and define a few xml files.
So basically when you just say Spring it is a just a framework. And by framework I mean lot of functionalities/jars. Like you may have core which has core functionality or aspectj etc. Spring MVC i.e model view controller is one such functionality offered by Spring framework. You can deffer processing of request to various controllers based on the pattern of URL requested. You can refer
Spring MVC hello world example
Spring framework can be visualized as an alternative to, replacement for, or even addition to the Enterprise JavaBeans (EJB) model as mentioned here. That means a framework to develop distributed, scalable, secured, transactional application.
Spring MVC can be thought of as an replacement to Struts, Stripes, Tapestry etc, i.e. Presentation layer framework.
Spring framework is the super set of Spring MVC.
Spring
An umbrella term to denote various projects, one of which is Spring Framework.
Spring MVC
The Spring Framework project has several features. One of them is Spring MVC.
Features of Spring Framework are -
Core Technologies: Dependency Injection, validation, data binding, type conversion, SpEL, AOP etc.
Testing
Data Access: Transactions, DAO support, JDBC, ORM etc.
Spring MVC and Spring WebFlux web frameworks.
Integration: JMS, JMX, email, scheduling etc.
Languages: Kotlin, Groovy, dynamic languages.
So, the Spring MVC feature allows developers to build applications following Model-view-controller design pattern using Spring Framework.
Other Spring projects
Spring Boot: For creating stand-alone Spring applications using Convention over configuration design paradigm.
Spring Data: For creating Spring-based programming model for data access. It has various modules like Spring Data JDBC, Spring Data JPA, Spring Data MongoDB etc.
Spring Security: Powerful and highly customizable authentication and access-control framework for both Authentication and Authorization.
And many other projects.
NOTE
Spring, Spring Framework and Spring MVC these terms are often used interchangeably among developers which sometimes creates confusion for people who already don't know the details.

Can i learn Spring MVC directly for web sites rather than basic Spring

Firstly, I want to know is Spring and Spring MVC different things.
IF they are different then can I jump directly to Spring MVC because I want to build website
and I have very less time to experiment and I want to start as soon possible.
Will spring MVC is sufficient without using hibernate or anything which I need to learn.
I know only core Java.
Spring MVC builds on top of Spring. So you need to know basics of Spring to use Spring MVC. And you doesn't need to learn Hibernate.
Spring
Introduction to Spring
Read chapters 1, 2 and 3 from reference manual
Spring MVC
Spring MVC step by step

Using Spring Security with EJB or Spring?

I wanted to build an application based on Java EE 6, but the security mechanisms of Java EE are not sufficient and a pain to with for my needs. Spring Security seems the best way to secure my application. Now I wonder if Spring Security + EJB is a good combination or if I should be better use Spring only.
I need method interception, ACLs and possibly URL pattern access control. The main problem I see is to use EJB interception with Spring Security. It is a problem? What other areas could be problematic?
Would you prefer Spring Security + EJB or Spring Security + Spring (only)?
As skaffman said the real question is Java EE vs. Spring. There is a nice comparison from JBoss.
Spring Security is distinct from the Spring Framework. They work well together, but Spring Security does not require you to use the Spring Framework underneath.
So in a very real sense, it doesn't matter, it becomes a question of whether you prefer EJB3 or Spring, regardless of Spring Security.
I am not very familiar with EJB but my understanding has always been that it is essentially a data-access technology, or a way to distribute services.
Spring itself, and the Spring Security module, is designed to be very lightweight and unobtrusive. If you are building a web application and using Spring Security for logins/security, then it doesn't care or even know if you are using EJB vs JDBC vs remoting technologies etc.
After having spent a lot of days trying to find a way to only uses springsecurity to secure the ejb, I've adopted kind of hybrid solution: JAAS + springsecurity.
The client uses JAAS to be authenticated to the ejb on the sever, I've created a custom JAAS LoginModule which delegates authentication to the springsecurity code.
EJBs to perform their logic use methods which are annotated with jsr250 annotations (RolesAllowed), and this part is fully handled by spring security.
In this way I've achieved a clear separation between ejb and spring security so my business code, secured by springsecurity, is fully portable to any other kind of ApplicationServer or it can even run as standalone application.

does spring provide 2 mvc platforms, grails and spring mvc?

Just reading spring in action, and I know there is a chapter on MVC that I havent' got to yet.
I also read about grails, is that another framework or built on top of spring?
Yes, Grails is built on Spring (and several other frameworks) and it uses Spring MVC to implement its MVC layer.

What are all the portlet classes in Spring mvc?

In Spring MVC there seem to be two parallel class hierarchies, one with portlet, one without.
What is that? Why is it so and what should I use.
That's because
In addition to supporting conventional
(servlet-based) Web development,
Spring also supports JSR-168 Portlet
development. As much as possible, the
Portlet MVC framework is a mirror
image of the Web MVC framework, and
also uses the same underlying view
abstractions and integration
technology.
The Spring documentation (Chapter 16. Portlet MVC Framework) provides more information about the differences.
To answer your last question: you should use the Portlet MVC framework if you are developing portlets (web applications to be deployed in a portal). If you are developing conventional web applications you should use the Web MVC framework.
You mean as opposed to servlet? The portlet MVC framework is specifically for development of JSR-168 (maybe JSR-286 too? not sure) portlets. There is a separate portlet hierarchy because the portlet MVC workflow differs from the servlet MVC workflow.
If you're developing a portlet, you want the portlet MVC framework. Otherwise, the Servlet MVC framework is what you need and you don't need to worry about the portlet stuff.

Categories