is spring boot only for building rest api? - spring

and if not what are more things that we can do with spring boot?
i know that we can build a whole web app(frontend and backend) in one spring boot application in the folder resource/template and resource/static but in the real world does somebody uses this method to create web application with the resource/template and resource/static?
and one more question what is used in the real world hibernate(with the SessionFactory or EntityManager) or JpaRepository in the spring data jpa?

No Spring Boot isn't just for REST APIs.
Spring Boot is "just" a mechanism for autoconfiguring a Spring Framework based application.
Therefore you can use and it does get used for all kinds of stuff.
REST APIs for webservices
Full web application using Spring MVC
SOAP services (or are they called SOAP dispensers?)
Reactive web applications
Command line tools
Batch jobs
Swing / JavaFX applications
...
Of course there are many more people writing web applications than Swing applications with or without Spring.
The kind of web application you describe and which I put under "Full web application using Spring MVC" is a very well established model and when done right way better aligned with the principles of REST than the average so called REST service. My very personal guess is: They will still be around when nobody remembers what Angular is.
For your additional question:
Your question sounds a little like the relation between JPA and Spring Data JPA might not be completely clear.
(see Spring Data JDBC / Spring Data JPA vs Hibernate)
Both are certainly used in real world projects. By definition more projects use JPA than Spring Data JPA since the first is a superset of the later.

This involves complete Spring history,
Actual motive of Spring was to enable loose coupling , so that unit tests can be easily performed . Spring MVC was for developing web applications with Model View Controller having their proper boundaries.
Then Spring Boot which enabled developer to focus on business logic then configurations. That's why spring boot is a good choice for microservices.
For JPA or hibernate query , many people prefer using JPARepositoy as again you just have to define entity for the repository and Spring boot automatically provides you queries like findById and so on.
In short Spring boot have made it really easy to run the applications with different configurations and environment smoothly.

Related

Spring Boot and Spring MVC are actually frameworks or not?

I know that the Spring Framework is a Framework, but the emergence of Spring Boot and Spring MVC makes me confused whether it is a framework or just one of the modules that Spring Framework has?
Yes.Spring is the most popular application framework for develop java base web application and spring framework core feature can be use any java application.
Also many people refer to Spring web MVC as a framework.
There is nothing wrong with that.
In other words, the spring web MVC is a part of the spring framework that is designed to implement web part in our application.
spring framework img
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.
Spring Boot Framework is widely used to develop REST APIs
If analyzed in depth Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications.
In short, Spring Boot is the combination of Spring Framework and Embedded Servers.
spring boot img
read more Web MVC
read more Spring boot

Will Spring Boot support WAR deployment of Spring Webflux applications in the future?

I know that Spring Boot, in contrast to Spring Framework, does not support WAR deployment for Spring WebFlux applications. My question is simple: will it ever in the future?
My use case is this: we have a lot of customers that still live in the traditional "we deploy everything on application server X" world. So although we would like to push standalone JARs, they are not ready (yet). We heavily use Spring Boot, and would really like to continue to do so, so abandoning that is not an option.
We are building reactive applications and would like to use Spring WebFlux for that, but we still need to deploy to application servers, so that is not an option. In the meantime we avoid Spring WebFlux and simply use Controllers, which works, but is not as elegant. Hence my question.
There are no plans to support Spring WebFlux with war deployments. However, you can use reactive return types, Reactor's Mono and Flux and those from RxJava, with Spring MVC packaged and deployed as war. That will allow you to build an entire reactive pipeline as you would with WebFlux, but deployed to an application server. It doesn't give you all of the benefits of full-blown reactive (no event loop-based concurrency, for example), but it can be a good middle ground for those in your situation.

Spring contract-first REST

I have a Spring web application - which doesn't use Spring-based GUI, but Wicket - and I would like to build contract-first REST services.
I already have a contract defined in Swagger and I generate model and API artifacts. Swagger codegen generates either Spring Boot artifacts, or Spring MVC ones.
My intention is to use ideally just a model, and maybe API (controllers) from this generated code. But up to my knowledge/research, there is no simple way to have just simple REST service without MVC/Boot boilerplate.
Therefore my questions are:
Is it possible to build lightweight Spring-based REST service, without having "heavy" dependency of full Spring MVC/Spring Boot?
If not, which approach is more lightweight? Spring Boot, or Spring MVC?
You are misinterpreting the Spring ecosystem.
Spring MVC is THE rest web and web service library within Spring portfolio.
The same way as Spring-WS is THE soap web service library.
They are very similar in architecture and style of use.
The fact that Spring MVC is bundled with Spring Framework does not change the situation.
Spring Boot does not bring any new REST offering. It is just a bootstrap mechanism to start Java web server with web app already deployed from a plain main() method. Therefore if you see "Building REST web services with Spring Boot", it just means that it is Spring MVC bootstrapped by Spring Boot.
Therefore, the question to what is more lightweight is straightforward: Spring MVC.
To answer the question #2:
The usage of Spring MVC is more lighweight, then usage of Spring Boot:
Size of the WAR archive:
6,1 MB for Spring MVC
9,2 MB for Spring Boot
Number of libraries in WAR archive:
12 for Spring MVC
28 for Spring Boot

Can you use (any) Spring's functionality outside of Spring (Boot)?

I have just built a RESTful web service with Spring Boot.
I now want to utilise the RESTful web service and start making calls to it by building a java console application (eventually adding GUI and security).
I was wondering if I can use any of the Spring functionality outside of the Spring (Boot) environment and use it in my java console application? For example, can I use Spring's RestTemplate in my non-Spring java application to make the REST api calls? I am new to Spring and I want to stick as close to Spring as possible. I think you can't, but I just want to make sure.
If not possible, I know you can create non-web application with Spring. Is it possible to integrate a GUI? Might not be best practice, just exploring what is possible and conventional.
Spring Boot is not coupled, in any way, to an application type. You can run command-line only apps, batch apps, web apps or any other kind of apps with it. You can even benefit from Spring Boot's auto-configuration.
In the case of the RestTemplate you may want to import spring-web directly rather than spring-boot-starter-web. Or you could add the starter and exclude the embedded container (spring-boot-starter-tomcat). Spring Boot will auto-adapt and not start an embedded web server in that case.

Spring 3.2 web application and android client

I have a Web application with a db and it uses spring framework, hibernate etc. I need to send data from a mobile client (iphone,android) to web application like login, insert, update db etc. There are many ways to do that I think, however I am looking for a good solution. What would you prefer? Spring Security? REST?
Yes, spring-security to secure your service, and spring-web && spring-mvc with jackson dependencies to create an annotated rest service that you can host in something like tomcat.

Resources