Spring Boot makes it easy to create stand-alone, production-grade spring based applications that you can "just run".
What is Spring?
- Application framework
- Programming and configuration model
- Infrastructure support
Problem with Spring
- Huge framework
- Multiple setup steps
- Multiple configuration steps
- Multiple build and deploy steps
Why do we need Spring Boot?
- Due to the problems in spring framework, spring boot comes.
- Opinionated
- Convention over configuration
- Stand alone
- Production ready
Spring Boot Features
Configuration and Customization
Lecture -7 (Maven):
- Maven is a project management tool that is based on project object model (POM). It is used for project build, dependency, and documentation. In short, maven is a tool that can be used for building and managing any java based project.
- Maven lets you declare all the dependencies that you want in a single file, you do not have to download the jars and add it to your class path, you just create pom.xml and list dependencies there and run maven command. This file contains a list of all your dependencies that maven (dependency tool management) needs to know.
Starting spring Boot
- Sets up default configuration
- Starts Spring application context
- Performs class path scan
- Starts Tomcat server
Controller:
A controller is basically a java class that has certain annotations marked. This annotation lets spring know what is the URL that you are mapping into and what should happen when the request comes to that URL.
What are differences between spring and spring boot? (interview question)
Spring | Spring Boot |
|
|
What is Spring Boot and mention the need for it?
Spring Boot is a Spring module which aims to simplify the use of the spring framework for java development.
Spring Boot framework comes with
- Auto dependency Resolution
- Embedded HTTP servers
- Auto configuration
- Management endpoints
- spring Boot CLI
Advantages of Spring Boot
- Provides autoconfiguration to load a set of default configuration for a quick start of the application
- Creates stand alone applications with a range of non-functional features that are common to large classes of project
- Spring boot comes with embedded tomcat, servlet containers to avoid the usage of WAR files
- Spring Boot provides an opinionated view to reduce the developer effort and simplify maven configuration
- Provides CLI tool to develop and test applications
- Comes with Spring Boot starters to ensure dependency management and also provides various security metrics
- Consists of a wide range of APIs for monitoring and managing applications in dev and prod
- Integrates with Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security easily by avoiding boilerplate code
How to create Spring Boot application using Maven?
There are various approaches to create a Spring Boot application using maven:
- Spring Boot CLI
- Spring Boot Project Wizard
- Spring Boot Initializer
- Spring Maven Project
What are possible sources of external configuration?
The most possible source of external configuration are:
- Application Properties
- Command Line Properties
- Profile Specific Properties
What are the Spring Boot starters?
- spring-boot-starter
- spring-boot-starter-jdbc
- spring-boot-starter-web
- spring-boot-starter-data-jpa
- spring-boot-starter-security
- spring-boot-starter-aop
- spring-boot-starter-test
Explain Spring Actuator and its advantages
Spring Actuator is a cool feature of Spring Boot with the help of which you can see what is happening inside a running application.
- The Spring Actuator provides a very easy way to access the production-ready REST points and fetch all kinds of information from the web
- These points are secured using spring security's content negotiation strategy
What is Spring Boot dependency management?
Spring Boot dependency management is used to manage dependencies and configuration automatically without you specifying the version for any of that dependencies.
1. RestTemplate class
Accessing a third-party REST service inside a Spring application revolves around the use of the Spring RestTemplate class. The RestTemplate class is designed on the same principles as the many other Spring *Template classes (e.g., JdbcTemplate, JmsTemplate ), providing a simplified approach with default behaviors for performing complex tasks. RestTemplate class is designed to call REST services.
2. Spring RestTemplate – HTTP GET Method Example
- getForObject(url, classType) – retrieve a representation by doing a GET on the URL. The response (if any) is unmarshalled to given class type and returned.
- getForEntity(url, responseType) – retrieve a representation as ResponseEntity by doing a GET on the URL.
- exchange(requestEntity, responseType) – execute the specified request and return the response as ResponseEntity.
- execute(url, httpMethod, requestCallback, responseExtractor) – execute the httpMethod to the given URI template, preparing the request with the RequestCallback, and reading the response with a ResponseExtractor.
Rest Template is used to create applications that consume RESTful Web Services. You can use the exchange() method to consume the web services for all HTTP methods.
References:
Spring Rest Template
Spring Rest Template
No comments:
Post a Comment