Spring Boot 2

Related Tags

Tutorials

Spring Boot

Spring Boot Tutorial

Learn Spring Boot with the following in-depth tutorials, covering from basic to advanced concepts such as packaging and monitoring.

Spring Boot @DataJpaTest

Spring boot @DataJpaTest annotation focuses on JPA components and apply configuration only relevant to JPA tests. It helps in testing @Repository classes.

Spring Boot DataSource Configuration with HikariCP Examples

Configure a DataSource in Spring Boot 4 with spring.datasource.url, username and password, and Spring Boot creates a HikariCP pool. Tested examples for pool tuning, DataSourceBuilder, a second DataSource, schema.sql and data.sql, and tests with H2 and Testcontainers.

AOP with Spring Boot: Annotation Example

Learn to implement AOP in Spring Boot applications and add different aop advices using AspectJ to support cross-cutting concerns, such as logging, profiling, caching, and transaction management.

Spring Boot @MockBean Example

Spring boot @MockBean annotation used to add mocks to a Spring ApplicationContext. In this tutorial, we will learn the different ways to use this annotation.

Spring Boot Integration Test With @SpringBootTest and H2

Write Spring Boot integration tests that start the real app with @SpringBootTest, call the REST API over HTTP with RestTestClient and check an H2 database. Covers @Sql test data, @MockitoBean for external systems, MockMvc, TestRestTemplate in Spring Boot 4, Failsafe and context caching.

Spring Boot Disable Startup Banner

To disable the spring boot banner logo from the console or log files, we can make changes in 3 possible ways i.e. programmatically, properties, or startup arguments. 1. Disable Banner Programmatically Set banner mode in the program using setBannerMode(Banner.Mode.OFF) method call which starts the application. 2. Disable Banner using Properties …

Spring Boot Annotations

Learn about some frequently used spring boot annotations as well as which work behind the scene. e.g. @SpringBootApplication and @EnableAutoConfiguration.

Configure Hibernate with Spring Boot

Learn to configure hibernate/JPA support in Spring Boot2 applications, along with creating entity classes and extending inbuilt JpaRepository interfaces.

Spring Boot Mockito JUnit Example: Unit Test a Service

Unit test a Spring Boot service with JUnit and Mockito. Mock the repository with @Mock, build the service with @InjectMocks, stub with when().thenReturn() and check calls with verify(). Also covers @MockitoBean in @SpringBootTest, thenThrow, ArgumentCaptor, BDDMockito, strict stubs and the Mockito Java agent on Java 21+.

Spring Boot MockMvc Example with @WebMvcTest and MockitoBean

Test Spring Boot REST controllers with MockMvc and @WebMvcTest. Replace the service with a @MockitoBean mock and send GET, POST, PUT and DELETE requests with JSON. Then check status codes, validation errors and @RestControllerAdvice responses. Also covers MockMvcTester (AssertJ) and real andDo(print()) output on Spring Boot 4.1.1.

Spring Boot Multi-Module Maven Project

Learn to create a spring boot project having multiple modules. The parent project will work as a container for base maven configurations. The child modules will be actual spring boot projects – inheriting the maven properties from the parent project. 1. Parent Spring Boot Project The parent project is single …

Basic Auth with Spring RestTemplate

Learn to add basic authentication to http requests invoked by Spring RestTemplate while accessing rest apis over the network. 1. Maven dependencies To work with Spring RestTemplate and HttpClient API, we must include spring-boot-starter-web and httpclient dependencies in pom.xml file. In this RestTemplate basic authentication tutorial, we are using dependencies. …

Securing Spring Boot REST API with Basic Auth

Learn to use basic authentication to secure the REST APIs created in a Spring boot application. The secured API will ask for user authentication credentials before giving access to the API response. 1. Maven Dependency The simplest way to add all required jars is to add the latest version of …

Configure Timeouts with Spring RestTemplate

In this Spring boot2 RestTemplate timeout example, learn to configure connection timeout and read timeout in Spring RestTemplate with example. 1. Default Timeout By default, RestTemplate uses SimpleClientHttpRequestFactory which depends on the default configuration of HttpURLConnection. Look inside the class source, and you will find this. By default, RestTemplate uses …

Spring Boot RestTemplate GET Example

In this, Spring Boot RestTemplate GET request example, learn to use RestTemplate to invoke HTTP GET API and verify the response status code and the response entity body. To create the rest APIs, use the sourcecode provided in spring boot rest api example. 1. Setup Start with including the latest …

Testing POST APIs using Spring Boot TestRestTemplate

Learn to consume HTTP POST REST API with Spring TestRestTemplate. In this post request test example, we will be sending request body along with request headers. 1. Maven dependencies Make sure, you have spring-boot-starter-test dependency in your project to get access to TestRestTemplate class in runtime. If you are using …

Spring Boot Retry Example

Learn to use Spring retry module for implementing retry-based remote API invocations that can handle runtime exceptions or network failures.

Spring RestTemplateBuilder Example

Learn to use Spring RestTemplateBuilder to create or build RestTemplate bean which can be used to send HTTP requests. 1. Default RestTemplateBuilder To inject RestTemplateBuilder, pass it as a constructor argument in the service class. 2. Custom RestTemplateBuilder To create custom RestTemplateBuilder, create @Bean of type RestTemplateBuilder in Spring context. …

Log Request and Response with Spring RestTemplate

In this Spring boot rest interceptor example, learn to use ClientHttpRequestInterceptor with Spring RestTemplate to log request and response headers and body in Spring AOP style. 1. Spring REST Interceptor Usages We can use this interceptor for many useful tasks. 2. REST Interceptor to Log Requests and Responses Below given …

Configuring HttpClient with Spring RestTemplate

We have already gone through the RestTemplate examples for accessing REST APIs inside spring application. In this example, we are extending the configuration to use Apache HttpClient 4. The purpose of this tutorial is to give you pre-cooked recipe for little head-start, and save you from writing all bits and pieces.

Spring Boot Dev Tools Tutorial

The Spring boot dev tools module provides a lot of useful developer features for improving the development experience such as caching static resources, automatic restarts, live reload, global settings and running the remote applications. 1. Enabling Dev Tools Module Enabling dev tools in the spring boot application is very easy. …

Spring Boot2 @SpringBootApplication Auto Configuration

String boot is very easy to use and it does a lot of things under the hood, you might not be aware of. In future, a good developer will be who will know exactly what is going on behind spring boot auto configuration, how to use it in your favor and how to disable certain sections which you do not want into your project.

Spring Boot CORS Configuration Examples

Spring CORS helps in serving web content from multiple domains into browsers who usually have the same-origin security policy. In this example, we will learn to enable CORS support in Spring MVC application at method and global level.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.