Spring-boot Spring-MVC application with jsp views and Swagger-ui - spring-boot

We have a Spring-boot application that has jsps for view. We are writing REST services to get the data from back-end.
Since the service needs to return a view, it is annotated with #Controller.
How can I implement it such that I can also test these services with Swagger but be able to return the view string from the REST endpoint?
Also examples mention to use #RestController, which I cannot use because of the need to return a view.
Thank you

Related

How will swagger work with spring boot if there is no rest controller, no request mapping annotation?

In my service there are only POJOs present but I don't need any controller to send them from any API, I just want to make a swagger documentation but they say there is no way to make swagger without the rest controller. Is there any way?
Generally swagger is used for documenting REST api but still you tweak it. Hope you are looking to generate schema/ dtos

Is springBoot in my case implementing the MVC pattern?

I am creating an application which has a front end developped using Angular, and a backend developped using SpringBoot.
The problem is that the backend has controllers with request mappings and models (services and repositories) and no views , so does it really implement the MVC pattern?
I have read in this article " Spring MVC or Spring Boot" that spring MVC which itslef implements the MVC pattern is a part of spring boot, so basically spring boot is MVC, which is true when you have views and HTML pages in your project, but in my case i can't talk about views since i am sending and recieving JSON data from a restful API.
According to https://www.wikiwand.com/en/Model%E2%80%93view%E2%80%93controller
view means presentation of the model in a particular format.
I think it is good definition. Particular format in case of backend for REST API happen to be JSON or XML.
From the same page
Some web MVC frameworks take a thin client approach that places almost
the entire model, view and controller logic on the server. In this
approach, the client sends either hyperlink requests or form
submissions to the controller and then receives a complete and updated
web page (or other document) from the view; the model exists entirely
on the server.
In your case the View would be the front-end. The View is the presentation of the data in a human understandable way.
So I believe the View in your case would be the front-end app.

Spring rest and spring web mvc

I have an application that has a web front end handled by spring MVC as well as the same services should be exposed as REST services. So the MVC controllers and rest controllers doing nearly the same thing which results in duplicate code. Now, the question is what is the best practice for the current scenario?
You can refactor your MVC controllers to isolate computation/code services within a #Service or #Component classes and call those from your rest controller as well as MVC controller to get data out so at the same time you will be able to remove redundancy and you will be able to achieve both functionalities.

Spring Boot REST JSP

I have a working Spring BOOT application that has a custom security provider and REST API controllers. I would also like to add a GUI interface to the application for access from a browser through jsps, html, and a login page which uses my existing custom security provider I used with the REST APIs. Maybe using Spring MVC since that is needed for the REST API support. I could not find a single example of doing this on the web. Also, I do NOT want to use any web XML based configuration files - as I am currently only using Java config for the implementation of the REST APIs. I am also currently using SSL for REST API access through SSL in a Jetty embedded web container. Please help if you can? Thanks in advanced.
Paul there is a rather large amount of information on view technologies that are compatible with Spring BOOT. You need to decide what you want to use and do relevant research for it.
As a guiding hand here check this page out for just one of the many types:
http://kielczewski.eu/2014/04/spring-boot-mvc-application/
You may follow this procedure :
lets assume that u have an endpoint for which you need both REST and view controllers,your REST endpoint exposes your data in JSON as RESTController and your view Endpoint returns the view name as Simple old controller.
lets say your base url is at localhost:8080 and your endpoint of interest is /students
you could have both in same application but at different endpoints like this :
REST : localhost:8080/api/v1/students -- exposes json
VIEW : localhost:8080/students -- returns a view
hope this make clear ..

Spring annotation for REST layer

I'm developing a RESTful service using ApacheCXF. I'm using Spring to inject the bean at each layer. I've three layer - REST layer, Service layer (Business logic layer) and DAO layer. I understand that we can annotate Service layer with #Service and DAO layer with #Repository but how do we annotate Rest class ? Do you suggest to annotate it with #Controller ? I've seen many examples where Rest class is annotated as #Controller if you're developing REST using Spring MVC. IMO, Spring MVC comes into play if you have deal with presentation layer as well (I may be wrong, don't have much idea about it) but this is just a web service which is hosted on one server to consume some data by some other application. I've not used Spring MVC in my past, but when would you suggest to develop REST services using Spring MVC? What's the benefit ?
If you're already using Spring, then Spring MVC is the way to write a RESTful service.
Prior to Spring 3, Spring MVC was very much focussed on traditional model-view-controller web apps that typically returned HTML to a web browser. Spring 3 added support for building RESTful services using Spring #Controllers typically configured to return JSON or XML payloads.
Rather than rehashing what's already been written, this blog post is a good introduction to the REST support that was added in Spring 3 and outlines a number of the benefits.

Resources