parent
fa9d8d6656
commit
fc6e8048a7
49 changed files with 120 additions and 501 deletions
@ -1,21 +1,11 @@ |
||||
# Spring mvc |
||||
# Spring MVC |
||||
|
||||
Spring MVC is a framework for building web applications in Java. It is part of the Spring Framework, which is a larger ecosystem of tools for building Java applications. Spring MVC is built on the Model-View-Controller (MVC) design pattern, which helps to separate the concerns of the application into three distinct components: the Model, the View, and the Controller. |
||||
|
||||
The Model represents the data and business logic of the application. It is typically implemented as a set of Java objects that encapsulate the data and behavior of the application. |
||||
|
||||
The View is responsible for displaying the data to the user. In Spring MVC, views are typically implemented as JSPs (JavaServer Pages) or Thymeleaf templates, but other view technologies can also be used. |
||||
|
||||
The Controller handles incoming requests from the user and directs them to the appropriate Model and View. In Spring MVC, controllers are typically implemented as Java classes that are annotated with the @Controller annotation. |
||||
|
||||
Spring MVC provides a powerful and flexible way to build web applications, and it integrates well with other parts of the Spring ecosystem, such as Spring Security for authentication and authorization, and Spring Data for data access. |
||||
|
||||
The Spring Framework is able to handle the request/response flow with servlet and handlers, that's why it is known as "Spring Web MVC" or just "Spring MVC". |
||||
|
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Spring MVC Tutorial](https://www.javatpoint.com/spring-mvc-tutorial) |
||||
- [Spring - MVC Framework](https://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm) |
||||
- [Web MVC framework](https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mvc.html) |
||||
|
||||
- [Web MVC framework](https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mvc.html) |
@ -1,20 +1,9 @@ |
||||
# Oauth2 |
||||
|
||||
OAuth2 is an open standard for authorization that allows users to share their private resources (such as an API, a website, or a service) with third-party applications, without having to reveal their login credentials. It works by allowing users to authorize third-party applications to access their resources, without having to share their passwords. |
||||
|
||||
In Spring, OAuth2 is implemented as a set of libraries, which can be integrated into your application to provide authentication and authorization functionality. The core library provides the OAuth2 protocol functionality, while additional libraries can be added to support different types of clients (such as web apps, mobile apps, or single-page apps), token stores, and user details services. |
||||
|
||||
One of the most common ways to implement OAuth2 in Spring is by using the Spring Security OAuth2 library, which provides support for both the authorization code grant type (for web apps) and the implicit grant type (for single-page apps). You can also use Spring Security to protect your resources, and to configure your application as an OAuth2 resource server. |
||||
|
||||
The OAuth2 authentication process can be complex and time-consuming, but the Spring Security OAuth2 library makes it easy to get started by providing a set of convenient configuration classes and annotations. |
||||
|
||||
You should also be aware that Spring Security OAuth 2 is in maintenance mode , the development of new features or fixes is discontinued and you would need to use Spring Security 5.5.x or Spring Security 6.0.x to get new features and also Spring Boot 2.3.x or Spring Boot 2.4.x is recommended, otherwise you may face issues with compatibility. |
||||
|
||||
It's important to read the documentation to understand how it works and what the best configuration options for your use case. |
||||
# OAuth2 |
||||
|
||||
Spring Security OAuth2 library provides support for both the authorization code grant type (for web apps) and the implicit grant type (for single-page apps). You can also use Spring Security to protect your resources, and to configure your application as an OAuth2 resource server. The OAuth2 authentication process can be complex and time-consuming, but the Spring Security OAuth2 library makes it easy to get started by providing a set of convenient configuration classes and annotations. |
||||
|
||||
Learn more about Oauth2 from the following resources: |
||||
|
||||
- [Spring Boot - OAuth2 with JWT](https://www.tutorialspoint.com/spring_boot/spring_boot_oauth2_with_jwt.htm#:~:text=OAuth2%20is%20an%20authorization%20framework,Client%20ID%20and%20Client%20secret.) |
||||
- [Spring Boot - OAuth2 with JWT](https://www.tutorialspoint.com/spring_boot/spring_boot_oauth2_with_jwt.htm) |
||||
- [Spring Boot and OAuth2](https://spring.io/guides/tutorials/spring-boot-oauth2/) |
||||
- [Spring Security](https://www.tutorialspoint.com/spring_security/spring_security_with_oauth2.htm) |
@ -1,19 +1,9 @@ |
||||
# Jwt authentication |
||||
# JWT Authentication |
||||
|
||||
JSON Web Token (JWT) is a JSON-based open standard for creating access tokens that assert some number of claims. These claims can be verified and trusted because they are digitally signed. JWT is typically used to protect API endpoints, and it enables the transmission of information that can be verified and trusted, because it is digitally signed. |
||||
|
||||
In a Spring application, you can use the Spring Security library to add JWT authentication and authorization to your API. The library provides a JWT-based authentication filter that you can add to your API endpoints. The filter will check the JWT that is included in the request header, and if it is valid, it will set the authentication information in the security context. You can then use the security context to perform authorization checks on the API endpoints. |
||||
|
||||
To use JWT in Spring, you'll need to first configure Spring Security to use JWT. You'll need to add the Spring Security and JJWT (Java JWT) dependencies to your project, and then configure the JWT filter and the authentication manager. |
||||
|
||||
Once the configuration is done, you will need to add the filter in your Security Configuration class with httpSecurity.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class); |
||||
|
||||
You will also need to create a service to create and validate JWT tokens, and then use it in your authentication controller. There are various library available for this like JWT Java library, Spring Security JWT. |
||||
Spring Security can be used to implement JWT Authentication and Authorization to your APIs. The library provides a JWT-based authentication filter that you can add to your API endpoints. The filter will check the JWT that is included in the request header, and if it is valid, it will set the authentication information in the security context. You can then use the security context to perform authorization checks on the API endpoints. |
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [JWT Token Authentication in Spring](https://springframework.guru/jwt-authentication-in-spring-microservices-jwt-token/#:~:text=Spring%20Boot%20Microservices%20requires%20authentication,securely%20transmitting%20information%20between%20parties.) |
||||
- [JWT Token Authentication in Spring](https://springframework.guru/jwt-authentication-in-spring-microservices-jwt-token/) |
||||
- [Spring Security with JWT for REST API](https://www.toptal.com/spring/spring-security-tutorial) |
||||
- [Spring Security - JWT](https://www.tutorialspoint.com/spring_security/spring_security_with_jwt.htm) |
||||
|
||||
|
||||
- [Spring Security - JWT](https://www.tutorialspoint.com/spring_security/spring_security_with_jwt.htm) |
@ -1,22 +1,9 @@ |
||||
# Spring boot starters |
||||
# Spring Boot Starters |
||||
|
||||
Spring Boot starters are a set of convenient dependency descriptors that you can include in your application. They provide a variety of functionality, such as security, data access, and web services, and help to minimize the amount of boilerplate code and configuration you need to write. |
||||
|
||||
Each starter POM (pom.xml) contains a list of dependencies and configurations that are known to work together. For example, the spring-boot-starter-web is a starter for building web, including RESTful, applications using Spring MVC. It includes the spring-webmvc and spring-web modules, as well as a number of other modules required for a typical web application. |
||||
|
||||
When you add a starter to your application's build, the necessary dependencies and configurations are automatically added, and you can start using the provided functionality right away. |
||||
|
||||
Here are a few examples of popular starters: |
||||
- spring-boot-starter-web: For building web applications and RESTful services. |
||||
- spring-boot-starter-data-jpa: For building Spring Data JPA based repositories and data access layer. |
||||
- spring-boot-starter-security: For adding Spring Security to your application. |
||||
- spring-boot-starter-test: For adding test dependencies and libraries such as JUnit, AssertJ and Hamcrest, for writing unit and integration tests. |
||||
|
||||
There are more than 20+ starters available for various use-cases, with more being added as new features are introduced in Spring Boot. Using starters can make it easier to add functionality to your application and it gives you a set of well-known and well-tested dependencies, configuration, and defaults to help you get started quickly. |
||||
|
||||
For more information, visit the following links: |
||||
|
||||
- [Intro to Spring Boot Starters](https://www.baeldung.com/spring-boot-starters) |
||||
- [Spring Boot Starters](https://www.javatpoint.com/spring-boot-starters) |
||||
- [Starters in Spring Boot](https://www.geeksforgeeks.org/spring-boot-starters/) |
||||
|
||||
- [Starters in Spring Boot](https://www.geeksforgeeks.org/spring-boot-starters/) |
@ -1,22 +1,9 @@ |
||||
# Autconfiguration |
||||
|
||||
Spring Autoconfiguration is a feature of Spring Boot that automatically configures beans and other components based on the presence of certain classes and properties on the classpath. This makes it easy to add functionality to your application without having to write a lot of boilerplate configuration code. |
||||
|
||||
When you include a dependency in your application, Spring Boot will automatically look for a corresponding "auto-configuration" class that can configure the necessary beans and other components. For example, if you include the spring-boot-starter-web dependency in your application, Spring Boot will automatically configure a DispatcherServlet and other components necessary for building web applications. |
||||
|
||||
Auto-configurations can be fine-tuned by providing specific properties in the application.properties, application.yml or other configuration files. Spring Boot uses these properties to adjust its behavior and configure beans accordingly. |
||||
|
||||
For example, if you want to change the default data source for your application, you can include the properties for a different data source and Spring Boot will automatically configure a DataSource bean for it. |
||||
|
||||
Spring Boot also provides a set of annotations such as @EnableAutoConfiguration that can be used to enable or disable specific auto-configurations, such as @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) would disable the auto-configuration for the data-source. |
||||
|
||||
In summary, Spring Boot's Autoconfiguration is a powerful and convenient feature that makes it easy to configure beans and other components in your application based on the presence of certain dependencies and properties. It saves developer's time by reducing the need for boilerplate configuration code, and can be fine-tuned through properties and annotations, to provide a fine-grained control over the auto-configurations. |
||||
Spring Boot's Autoconfiguration is a powerful and convenient feature that makes it easy to configure beans and other components in your application based on the presence of certain dependencies and properties. It saves developer's time by reducing the need for boilerplate configuration code, and can be fine-tuned through properties and annotations, to provide a fine-grained control over the auto-configurations. |
||||
|
||||
For more information, visit the following links: |
||||
|
||||
- [Auto-configuration using Spring Boot](https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/using-boot-auto-configuration.html#:~:text=Spring%20Boot%20auto%2Dconfiguration%20attempts,configures%20an%20in%2Dmemory%20database.) |
||||
- [Auto-configuration using Spring Boot](https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/using-boot-auto-configuration.html) |
||||
- [Spring Boot Auto-configuration](https://www.javatpoint.com/spring-boot-auto-configuration) |
||||
- [What is Spring Boot Auto-configuration](https://www.geeksforgeeks.org/spring-boot-auto-configuration/) |
||||
|
||||
|
||||
|
||||
- [What is Spring Boot Auto-configuration](https://www.geeksforgeeks.org/spring-boot-auto-configuration/) |
@ -1,17 +1,9 @@ |
||||
# Embedded server |
||||
# Embedded Server |
||||
|
||||
Spring Embedded Server refers to the ability of Spring Boot applications to run an embedded web server, such as Tomcat, Jetty or Undertow, directly within the application, without the need to deploy it to a separate standalone web server. This makes it easy to develop and test web applications, as well as to deploy them in environments where a standalone web server may not be available or desirable. |
||||
|
||||
When you include the spring-boot-starter-web dependency in your application, Spring Boot automatically configures and starts an embedded web server, such as Tomcat, to run your application. This means that you don't need to install and configure a separate web server, such as Apache Tomcat, to run your application. |
||||
|
||||
Embedded servers are also lightweight and easy to start and stop, which makes it easier to test your application. You can start and stop the embedded server programmatically and run integration tests on your controllers, endpoints and other web components. |
||||
|
||||
You can also configure the port and other options of the embedded server by specifying properties in the application.properties or application.yml file. |
||||
|
||||
In summary, Spring Boot's Embedded Server feature is a convenient and powerful feature that allows you to run a web server directly within your application, without the need to deploy it to a separate standalone web server. This makes it easy to develop, test, and deploy web applications, and it's also lightweight, easy to start and stop, and easy to configure. |
||||
Spring Boot's Embedded Server feature is a convenient and powerful feature that allows you to run a web server directly within your application, without the need to deploy it to a separate standalone web server. This makes it easy to develop, test, and deploy web applications, and it's also lightweight, easy to start and stop, and easy to configure. |
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Embedded Servers in Spring](https://subscription.packtpub.com/book/application-development/9781789132588/3/ch03lvl1sec24/embedded-servers#:~:text=Spring%20Boot%20brings%20in%20the,is%20installed%20on%20the%20server.) |
||||
- [Embedded Servers in Spring](https://subscription.packtpub.com/book/application-development/9781789132588/3/ch03lvl1sec24/embedded-servers) |
||||
- [What is an Embedded Server? (Spring Boot)](https://www.springboottutorial.com/java-programmer-essentials-what-is-an-embedded-server) |
||||
- [Embedded Web Servers ‘How-to’ guides](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/howto-embedded-web-servers.html) |
@ -1,49 +1,17 @@ |
||||
# Entity lifecycle |
||||
|
||||
Here we will learn about Hibernate Lifecycle or in other words, we can say that we will learn about the lifecycle of the mapped instances of the entity/object classes in hibernate. In Hibernate, we can either create a new object of an entity and store it into the database, or we can fetch the existing data of an entity from the database. These entity is connected with the lifecycle and each object of entity passes through the various stages of the lifecycle. |
||||
In Hibernate, we can either create a new object of an entity and store it into the database, or we can fetch the existing data of an entity from the database. These entity is connected with the lifecycle and each object of entity passes through the various stages of the lifecycle. |
||||
|
||||
There are mainly four states of the Hibernate Lifecycle : |
||||
|
||||
1. Transient State |
||||
2. Persistent State |
||||
3. Detached State |
||||
4. Removed State |
||||
|
||||
|
||||
**State 1: Transient State** |
||||
|
||||
The transient state is the first state of an entity object. When we instantiate an object of a POJO class using the new operator then the object is in the transient state. This object is not connected with any hibernate session. As it is not connected to any Hibernate Session, So this state is not connected to any database table. So, if we make any changes in the data of the POJO Class then the database table is not altered. Transient objects are independent of Hibernate, and they exist in the heap memory. |
||||
|
||||
Changing new object to Transient State. There are two layouts in which transient state will occur as follows: |
||||
|
||||
- When objects are generated by an application but are not connected to any session. |
||||
- The objects are generated by a closed session. |
||||
|
||||
|
||||
**State 2: Persistent State** |
||||
|
||||
Once the object is connected with the Hibernate Session then the object moves into the Persistent State. So, there are two ways to convert the Transient State to the Persistent State : |
||||
|
||||
- Using the hibernated session, save the entity object into the database table. |
||||
- Using the hibernated session, load the entity object into the database table. |
||||
|
||||
In this state. each object represents one row in the database table. Therefore, if we make any changes in the data then hibernate will detect these changes and make changes in the database table. |
||||
|
||||
|
||||
**State 3: Detached State** |
||||
|
||||
For converting an object from Persistent State to Detached State, we either have to close the session or we have to clear its cache. As the session is closed here or the cache is cleared, then any changes made to the data will not affect the database table. Whenever needed, the detached object can be reconnected to a new hibernate session. |
||||
|
||||
|
||||
|
||||
**State 4: Removed State** |
||||
|
||||
In the hibernate lifecycle it is the last state. In the removed state, when the entity object is deleted from the database then the entity object is known to be in the removed state. It is done by calling the delete() operation. As the entity object is in the removed state, if any change will be done in the data will not affect the database table. |
||||
|
||||
- Transient State |
||||
- Persistent State |
||||
- Detached State |
||||
- Removed State |
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Hibernate Lifecycle](https://www.geeksforgeeks.org/hibernate-lifecycle/) |
||||
- [Entity Lifecycle in Hibernate](https://www.javatpoint.com/hibernate-lifecycle) |
||||
- [Hibernate Entity Lifecycle & and its state](https://www.baeldung.com/hibernate-entity-lifecycle#:~:text=Every%20Hibernate%20entity%20naturally%20has,able%20to%20use%20Hibernate%20properly.) |
||||
- [Hibernate Lifecycle](https://www.geeksforgeeks.org/hibernate-lifecycle/) |
||||
- [Entity Lifecycle in Hibernate](https://www.javatpoint.com/hibernate-lifecycle) |
||||
- [Hibernate Entity Lifecycle & and its state](https://www.baeldung.com/hibernate-entity-lifecycle) |
||||
|
||||
|
@ -1,10 +1,9 @@ |
||||
# Spring data jpa |
||||
# Spring Data JPA |
||||
|
||||
Spring Data JPA is a library that makes it easy to implement Java Persistence API (JPA) based repositories (a fancy word for "DAO") for Spring applications. It's an abstraction on top of JPA that allows you to use a simpler and more convenient API for performing CRUD (Create, Read, Update, Delete) operations on databases. Spring Data JPA also provides additional functionality such as pagination, dynamic query generation, and more. |
||||
|
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Spring Data JPA](https://spring.io/projects/spring-data-jpa#:~:text=Spring%20Data%20JPA%20aims%20to,will%20provide%20the%20implementation%20automatically.) |
||||
- [Spring Data JPA](https://spring.io/projects/spring-data-jpa) |
||||
- [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa) |
||||
- [Spring Data JPA Tutorial](https://www.javatpoint.com/spring-and-jpa-integration) |
||||
|
@ -1,23 +1,12 @@ |
||||
# Spring data mongodb |
||||
# Spring Data Mongodb |
||||
|
||||
Spring Data for MongoDB is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for new datastores while retaining store-specific features and capabilities |
||||
|
||||
The Spring Data MongoDB project provides integration with the MongoDB document database. Key functional areas of Spring Data MongoDB are a POJO centric model for interacting with a MongoDB DBCollection and easily writing a Repository style data access layer. |
||||
|
||||
Some of its features are as follow: |
||||
|
||||
- Spring configuration support using Java based @Configuration classes or an XML namespace for a Mongo driver instance and replica sets. |
||||
- MongoTemplate helper class that increases productivity performing common Mongo operations. Includes integrated object mapping between documents and POJOs. |
||||
- Exception translation into Spring’s portable Data Access Exception hierarchy. |
||||
- Feature Rich Object Mapping integrated with Spring’s Conversion Service. |
||||
- Annotation based mapping metadata but extensible to support other metadata formats. |
||||
- Persistence and mapping lifecycle events. |
||||
- Low-level mapping using MongoReader/MongoWriter abstractions etc. |
||||
|
||||
|
||||
For more resources on spring data mongodb, visit the following links: |
||||
|
||||
- [Spring Data MongoDB](https://spring.io/projects/spring-data-mongodb#:~:text=Spring%20Data%20for%20MongoDB%20is,store%2Dspecific%20features%20and%20capabilities.) |
||||
- [Spring Data MongoDB](https://spring.io/projects/spring-data-mongodb) |
||||
- [Introduction to Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-tutorial) |
||||
- [Spring Boot Integration with MongoDB Tutorial](https://www.mongodb.com/compatibility/spring-boot) |
||||
|
||||
|
@ -1,9 +1,9 @@ |
||||
# Spring data jdbc |
||||
# Spring Data JDBC |
||||
|
||||
Spring Data JDBC is a part of the Spring Data project that provides support for using JDBC (Java Database Connectivity) to interact with relational databases. It is designed to provide a simple and consistent programming model for interacting with databases using JDBC, while still allowing for the full power of JDBC to be used if needed. Spring Data JDBC provides a set of abstraction and utility classes that simplify the task of working with databases, such as a simple template class for executing SQL queries, a repository abstraction for implementing data access objects (DAOs), and support for pagination and sorting of query results. It works with both Java and Kotlin. |
||||
|
||||
Visit the following links for more resources on spring data jdbc: |
||||
|
||||
- [Spring Data JDBC](https://spring.io/projects/spring-data-jdbc#:~:text=Spring%20Data%20JDBC%2C%20part%20of,that%20use%20data%20access%20technologies.) |
||||
- [Spring Data JDBC](https://spring.io/projects/spring-data-jdbc) |
||||
- [Spring Data JDBC - Reference Documentation](https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/) |
||||
- [Introduction to Spring Data JDBC](https://www.baeldung.com/spring-data-jdbc-intro) |
@ -1,10 +1,10 @@ |
||||
# Spring data |
||||
# Spring Data |
||||
|
||||
Spring Data is a collection of projects for data access in Spring-based applications. It provides a common interface for working with various types of data stores, including relational databases, NoSQL data stores, and cloud-based data services. The goal of Spring Data is to simplify data access in Spring applications by providing a consistent, high-level repository programming model across different data stores and data access technologies. This can help developers write less boilerplate code and focus on business logic, while still being able to take advantage of the full power of the underlying data store. |
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Spring Data](https://spring.io/projects/spring-data#:~:text=2022.0.0,of%20the%20underlying%20data%20store.) |
||||
- [Spring Data](https://spring.io/projects/spring-data) |
||||
- [Spring Data – One API To Rule Them All?](https://www.infoq.com/articles/spring-data-intro/) |
||||
- [What is JPA, Spring Data and Spring Data JPA](https://www.amitph.com/jpa-and-spring-data-jpa/) |
||||
|
||||
|
@ -1,16 +1,12 @@ |
||||
# Cloud config |
||||
# Cloud Config |
||||
|
||||
Spring Cloud Config is a library for managing configuration properties for distributed applications. It allows developers to externalize configuration properties for an application, so that they can be easily changed without modifying the application's code. It also provides a centralized server for storing and managing configuration properties for multiple applications, making it easy to update and rollback configurations across different environments. |
||||
|
||||
Spring Cloud Config Server is an HTTP server that provides a REST API for managing configuration properties. It can store configuration properties in a variety of back-ends such as a file system, a Git repository, or a database. The server also supports encryption and decryption of sensitive properties. |
||||
|
||||
Spring Cloud Config Client is a library that can be included in an application, and it connects to the Config Server to retrieve the properties needed for the application to run. The client can also be configured to automatically refresh the properties when they change, so that the application can pick up the new values without having to be restarted. |
||||
|
||||
By using Spring Cloud Config, developers can have a centralized and consistent approach for managing the configuration properties of their microservices or distributed applications, making it easy to modify the properties without having to change the code, also it helps in maintaining different environment configuration easily. |
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Spring Cloud Config](https://spring.io/projects/spring-cloud-config#:~:text=Spring%20Cloud%20Config%20provides%20server,for%20applications%20across%20all%20environments.) |
||||
- [Spring Cloud Config](https://spring.io/projects/spring-cloud-config) |
||||
- [Quick Intro to Spring Cloud Configuration](https://www.baeldung.com/spring-cloud-configuration) |
||||
- [Spring Boot - Cloud Configuration Server](https://www.tutorialspoint.com/spring_boot/spring_boot_cloud_configuration_server.htm) |
||||
|
||||
|
@ -1,13 +1,9 @@ |
||||
# Spring cloud openfeign |
||||
# Spring Cloud OpenFeign |
||||
|
||||
Spring Cloud OpenFeign is a library for creating declarative REST clients in Spring applications. It allows developers to easily make HTTP requests to other microservices or remote services, without having to manually write the low-level code to handle the requests and responses. OpenFeign is built on top of the OpenFeign declarative HTTP client, which is a simple, lightweight library for creating HTTP clients in Java. |
||||
|
||||
Spring Cloud OpenFeign provides a consistent, easy-to-use programming model for making RESTful calls, and it integrates seamlessly with Spring Cloud Netflix and Ribbon to provide load balancing and service discovery. It also supports other Spring projects such as Spring Security and Spring Retry. It uses interfaces and annotations to define the REST endpoints, so that the underlying HTTP request can be handled by Feign, allowing for more readable and easy to reason about code. |
||||
|
||||
With the help of OpenFeign, developers can write simple and clean code to call the other microservices, without having to worry about the underlying HTTP request and responses, it also provides a lot of features out of the box like Retry, Circuit breaker patterns, Load balancing etc. This makes the code more readable and easy to maintain, also make it easier to test. |
||||
|
||||
For more resources, visit the following links: |
||||
|
||||
- [Introduction to Spring Cloud OpenFeign](https://www.baeldung.com/spring-cloud-openfeign#:~:text=In%20this%20tutorial%2C%20we're,annotations%20and%20JAX%2DRS%20annotations.) |
||||
- [Introduction to Spring Cloud OpenFeign](https://www.baeldung.com/spring-cloud-openfeign) |
||||
- [Spring Cloud OpenFeign](https://spring.io/projects/spring-cloud-openfeign) |
||||
- [Simple Implementation of Spring Cloud OpenFeign](https://medium.com/javarevisited/simple-implementation-of-spring-cloud-openfeign-7f022630d01d) |
@ -1,21 +1,11 @@ |
||||
# Spring mvc |
||||
# Spring MVC |
||||
|
||||
Spring MVC is a web application framework that is part of the Spring Framework. It is designed to make it easy to build web applications using the Model-View-Controller (MVC) design pattern. |
||||
|
||||
In Spring MVC, the application is divided into three main components: the Model, the View, and the Controller. The Model represents the data and the business logic of the application, the View is responsible for generating the HTML that is sent to the client's web browser, and the Controller acts as an intermediary between the Model and the View, handling incoming HTTP requests and generating the appropriate response. |
||||
|
||||
The DispatcherServlet is the central point for handling requests in a Spring MVC application. It acts as the front controller, receiving all incoming requests and delegating responsibility to other components. |
||||
|
||||
The Spring Framework provides a rich set of features for building web applications, including support for data binding and validation, flexible view resolution, and different file format support, such as JSPs, Thymeleaf and others. It also provides other supporting components such as the Spring IoC container, which manages the lifecycle of the application's objects, and various interceptors that can be used to add additional functionality such as caching and security. |
||||
|
||||
Spring MVC promotes separation of concerns, testability and ease of testing, making it easy to build and maintain web applications. |
||||
|
||||
|
||||
For more information, visit the following links: |
||||
|
||||
- [Spring MVC Tutorial](https://www.javatpoint.com/spring-mvc-tutorial) |
||||
- [Spring - MVC Framework](https://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm) |
||||
- [Spring MVC Tutorial – Everything You Need To Know](https://www.edureka.co/blog/spring-mvc-tutorial/) |
||||
|
||||
|
||||
|
||||
- [Spring MVC Tutorial – Everything You Need To Know](https://www.edureka.co/blog/spring-mvc-tutorial/) |
@ -1,27 +1,9 @@ |
||||
# Spring boot test annotation |
||||
|
||||
|
||||
|
||||
Spring Boot provides several test annotations to make it easy to test Spring Boot applications. Some of the most commonly used annotations include: |
||||
|
||||
- @SpringBootTest: This annotation is used to create a fully-configured instance of the Spring ApplicationContext for testing. It can be used to test the application's components, including controllers, services, and repositories, in a real application environment. |
||||
|
||||
- @WebMvcTest: This annotation is used to test Spring MVC controllers and is typically used in combination with @MockBean or @AutoConfigureMockMvc to provide a mock environment. It can be used to test the controllers in isolation from the rest of the application. |
||||
|
||||
- @DataJpaTest : This annotation is used to test Spring Data JPA repositories and is typically used in combination with @AutoConfigureTestDatabase to provide a test database environment. It can be used to test the JPA repositories in isolation from the rest of the application. |
||||
|
||||
- @JsonTest : This annotation is used to test JSON serialization and deserialization. It can be used to test the JSON parsing and serialization functionality of the application. |
||||
|
||||
- @RestClientTest : This annotation is used to test Spring RestTemplate based clients. It can be used to test the Rest clients in isolation from the rest of the application |
||||
|
||||
These annotations can be used in conjunction with other testing libraries like JUnit, AssertJ, Hamcrest and Mockito to create powerful and flexible test suites for Spring Boot applications. Spring Boot also provide a set of TestExecutionListener that can be used to further customize the test setup |
||||
|
||||
Spring Boot's test annotations provide a powerful and flexible way to test Spring Boot applications, making it easy to test various aspects of the application, including the controllers, services, repositories, and JSON parsing functionality. |
||||
|
||||
|
||||
`@SpringBootTest` This annotation is used to create a fully-configured instance of the Spring ApplicationContext for testing. It can be used to test the application's components, including controllers, services, and repositories, in a real application environment. |
||||
|
||||
For more information, visit the following links: |
||||
|
||||
- [Testing with Spring Boot and @SpringBootTest](https://reflectoring.io/spring-boot-test/) |
||||
- [Annotation Interface SpringBootTest](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/SpringBootTest.html) |
||||
- [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing) |
||||
- [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing) |
@ -1,20 +1,9 @@ |
||||
# Mockbean annotation |
||||
# Mockbean Annotation |
||||
|
||||
MockBean is a Spring annotation that can be used to create a mock implementation of a bean in the Spring application context. When a test is annotated with MockBean, Spring creates a mock implementation of the specified bean and adds it to the application context. The mock bean can then be used to replace the real bean during testing. |
||||
|
||||
This annotation can be used to create a mock implementation of any type of bean, such as a service, repository, or controller. For example, if you have a service bean that interacts with a database, you can use MockBean to create a mock implementation of the service bean that can be used during testing, so that the test does not depend on the actual database. |
||||
|
||||
MockBean also provides several features like name, answer and more, that can be used to customize the mock creation and its behavior during test execution. |
||||
|
||||
MockBean can be used in conjunction with other testing libraries like JUnit, AssertJ, Hamcrest and Mockito to create powerful and flexible test suites. It is commonly used in conjunction with @WebMvcTest, @DataJpaTest, and other testing annotations to isolate specific parts of the application and test them in isolation. |
||||
|
||||
In summary MockBean is a powerful and flexible tool that can be used to create mock implementations of beans in a Spring application. It allows to replace real beans with mocks during testing, so that the tests do not depend on the actual implementation, but just the contract. It is a powerful tool to create isolated and focused tests. |
||||
`MockBean` is a Spring annotation that can be used to create a mock implementation of a bean in the Spring application context. When a test is annotated with MockBean, Spring creates a mock implementation of the specified bean and adds it to the application context. The mock bean can then be used to replace the real bean during testing. |
||||
|
||||
For more information, visit the following links: |
||||
|
||||
- [Mockito.mock() vs @Mock vs @MockBean](https://www.baeldung.com/java-spring-mockito-mock-mockbean#:~:text=Spring%20Boot's%20%40MockBean%20Annotation&text=The%20mock%20will%20replace%20any,service%2C%20needs%20to%20be%20mocked.) |
||||
- [Mockito.mock() vs @Mock vs @MockBean](https://www.baeldung.com/java-spring-mockito-mock-mockbean) |
||||
- [Spring Boot @MockBean Example](https://howtodoinjava.com/spring-boot2/testing/spring-mockbean-annotation/) |
||||
- [Annotation Interface MockBean](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/mock/mockito/MockBean.html) |
||||
|
||||
|
||||
|
||||
- [Annotation Interface MockBean](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/mock/mockito/MockBean.html) |
@ -1,27 +1,10 @@ |
||||
# Testing |
||||
|
||||
Spring Testing is a set of testing utilities for Spring applications that makes it easy to test the various components of a Spring application, including controllers, services, repositories, and other components. Spring Testing provides a rich set of testing annotations, utility classes and other features to aid in unit testing, integration testing and more. |
||||
|
||||
Spring Testing can be used in conjunction with various testing libraries like JUnit, AssertJ, Hamcrest and Mockito to create powerful and flexible test suites. |
||||
|
||||
Some of the key features of Spring Testing include: |
||||
|
||||
- Support for testing Spring MVC controllers using @WebMvcTest and MockMvc |
||||
- Support for testing Spring Data JPA repositories using @DataJpaTest |
||||
- Support for testing Spring's JSON serialization and deserialization using @JsonTest |
||||
- Support for testing Spring's RestTemplate based clients using @RestClientTest |
||||
- Support for creating and managing test slices of the Application context with @SpringBootTest, @WebMvcTest, @DataJpaTest and more. |
||||
|
||||
Spring Testing also provides a lot of utility classes and annotations to make testing Spring applications easier, such as TestEntityManager for-JPA testing, MockHttpServletRequest and MockHttpServletResponse for testing controllers, TestRestTemplate for testing RestTemplate clients, and more. |
||||
|
||||
Overall, Spring Testing is a robust and powerful set of testing utilities that makes it easy to test Spring applications, promote good testing practices, improve the quality of the code and catch issues early in the development process. |
||||
Spring provides a set of testing utilities that make it easy to test the various components of a Spring application, including controllers, services, repositories, and other components. It has a rich set of testing annotations, utility classes and other features to aid in unit testing, integration testing and more. |
||||
|
||||
|
||||
For more information, visit the following links: |
||||
|
||||
- [Spring Testing](https://industrialphysics.com/knowledgebase/articles/spring-testing/#:~:text=Spring%20testing%20on%20a%20universal,displacement%20in%20static%20testing%20applications.) |
||||
- [Spring Testing](https://industrialphysics.com/knowledgebase/articles/spring-testing/) |
||||
- [What Is Spring Testing?](https://www.developer.com/design/what-is-spring-testing/) |
||||
- [Complete Guide To Spring Testing](https://www.lambdatest.com/blog/spring-testing/) |
||||
|
||||
|
||||
|
||||
- [Complete Guide To Spring Testing](https://www.lambdatest.com/blog/spring-testing/) |
Loading…
Reference in new issue