Creating controller classes in spring framework - spring

I am developing an accounts related project using spring mvc. I have problem in creating controller classes. Like Action class in struts framework do we need to create separate controller for spring ie (individual controller for every UI pages). I stuck up here. How can I create a controller class? based on module or by UI pages?

If I correctly understand your question, You want to know the design of serving request. It is not necessary or a good practice to create controller for serving each request(page). I think you should go for module based controllers. You can follow MVC architecture to have a better understanding on coupling requests with controllers.Spring have mvc support. There are numerous tutorials in spring mvc.
Here is a demo of spring MVC.

Related

Spring MVC modules,subsystems and components

Let's say we have a Spring MVC project which is a banking web application. I am trying to identify the sub-systems ,modules and components of this project.
1.Subsystems - from what I have red the subsystems in MVC architecture are only 3- the Model,View and Controller is that correct?
2.Modules - are these a group of classes that do something particular as a group.For example LoginController.java,RegisterControler.java form a module let's call it Authentication
3.Components - for components I am not sure which they are in a Spring MVC project.
If someone can explain with examples in terms of a banking web application or other Spring MVC app it would be great!
Spring MVC follows the Model-View-Controller design pattern.
Model - A model contains the data of the application. A data can be a single object or a collection of objects.
Controller - A controller contains the business logic of an application. Here, the #Controller annotation is used to mark the class as the controller.
View - A view represents the provided information in a particular format. Generally, JSP+JSTL is used to create a view page. Although spring also supports other view technologies such as Apache Velocity, Thymeleaf and FreeMarker.
Spring Boot Framework has mainly four major Components.
Spring Boot Starters.
Spring Boot AutoConfigurator.
Spring Boot CLI.
Spring Boot Actuator.
Please check out : https://www.journaldev.com/7989/key-components-and-internals-of-spring-boot-framework
In project-specific terms,
Module: It can be something that can be built separately in an application. ex: Login Module, Sign-up module, Transactions module, etc., You can say a module is a group of components.
Sub-systems: As far as I know, subsystems are the service package related stuff.
Components: Annotating a class with #Component tells Spring that it is available for fulfilling injections.
Spring Component annotation is used to denote a class as a Component. It means that the Spring framework will autodetect these classes for dependency injection when annotation-based configuration and classpath scanning is used

How to implement a Model in Spring MVC?

I'm new to Spring MVC, and I have been working on Codeigniter in php for a while,
In Codeigniter you implement Controller and Model by extending the particular class,
Ex : class Blogmodel extends CI_Model {
but in Spring MVC I didn't see such an implementation, except for controllers. Please can somebody give me a brief introduction on how would I perform the tasks that I did in a Model class in PHP, using Spring Framework.
Spring MVC is a presentation layer framework.
Is it not tied to any persistence mechanism, but can work seamlessly with persistence models.
In Spring (as well as other Java enterprise frameworks) the persistence layer is implemented using JPA (of which Hibernate is an implementation).
Spring MVC can easily operate on the JPA Entities.
You normally don't extend or implement anything, you just create the classes for the models you're interested in having.
If the model is supposed to be persisted somewhere, for instance in a database, you normally annotate the class with #Entity.

Kendo UI for JSP- DataSource Servlet or RESTful service

I am new to Kendo UI framework. I would like to know whether I could use normal Servlets or RESTful service instead of Spring Controller for Kendo UI for JSP?
E.g. For the following grid example(http://demos.telerik.com/kendo-ui/web/grid/index.html), they have used Spring Controller class in data source, so instead of Spring Controller class, could it be possible to use servlets or RESTful service class for datasource?
Any help is highly appreciable.
Regards
Yes it is possible. This blog post shows how to do it: Building a better UI – JSP Wrappers part 2

How to integrate ExtJS with Spring Framework

How to integrate ExtJS with Spring IOC? I was able to integrate with Spring MVC?
I've done this type of integration, but I encountered some problems. The best solution for my case was:
The entire system was created using Rest requests where the ExtJS
through URL access query performed in the main application.
The structure was created using ExtJS MVC model. Helping build the models and structure requests.
A project like this is the Sonatype Nexus.
http://www.sonatype.org/nexus/

Experiences with integrating spring 3 mvc with GWT?

Given:
Spring 3.0 mvc has excellent REST support with one of the representation being JSON.
GWT simplifies development as UI is developed in java. But by default it uses RPC for client server interaction. But there is an option to use JSON.
Questions:
Can you share experiences with using Spring 3.0 mvc with GWT ?
What is the best approach to integrate these two frameworks?
Is the default GWT's MVP architecture only for client side and does it work well with JSON?
Thanks
Can you share experiences with using Spring 3.0 mvc with GWT ?
Yes. We've successfully built a whole large application around GWT and Spring MVC (1500 source files, 6 months in development).
Spring was the key to the project's success. Only with Spring we were able to test individually some pieces of the application on the server side.
What is the best approach to marry these two frameworks?
Ignore the default Servlet used by GWT and instead create your own Spring controller to handle incoming GWT-RPC requests. This blog post was the key to integrating the two techs.
We also successfully integrated other components: Flash for animated charts and third-party Javascript components for other stuff. These communicate with the server through JSON. So you have two or more kinds of URLs:
the *.rpc urls are for GWT components and are served by the Spring controller for gwt
the *.json urls are for other components and are served by another Spring controller.
Also, in our case, we shunned configuration with annotations and instead preferred configuration with the good old Spring XML files. They make it much more clear what's going on. Except for the #Required annotation; it's great to find spring beans that should be connected but aren't.
Is the default GWT's MVP architecture only for client side and does it work well with JSON?
GWT's MVP architecture works best if you follow the guide lines. Use GWT-RPC communication as Google suggests.
You can still have JSON for other client-side components.
Try this solution: GWT and Spring MVC Integration
It uses 3 classes. Its very simple, declarative and clear.
It's stupid to mix Spring MVC and GWT. Also it's stupid to mix Spring MVC and JSF... It's stupid to mix 2 MVC (MVP) frameworks together. But you can use Spring DI and GWT for sure!
You may want to check out Spring Roo. It will help you get started quickly with Spring MVC, especially when dealing with RESTful URLs. It also provides a means to automatically set up GWT "scaffolding" (GWT code to interact with the Spring MVC backend). Hope it helps!

Resources