➤ How to Code a Game
➤ Array Programs in Java
➤ Java Inline Thread Creation
➤ Java Custom Exception
➤ Hibernate vs JDBC
➤ Object Relational Mapping
➤ Check Oracle DB Size
➤ Check Oracle DB Version
➤ Generation of Computers
➤ XML Pros & Cons
➤ Git Analytics & Its Uses
➤ Top Skills for Cloud Professional
➤ How to Hire Best Candidates
➤ Scrum Master Roles & Work
➤ CyberSecurity in Python
➤ Protect from Cyber-Attack
➤ Solve App Development Challenges
➤ Top Chrome Extensions for Twitch Users
➤ Mistakes That Can Ruin Your Test Metric Program
Spring Boot Interview Questions | It covers various topics from Spring, Spring Boot, Spring Data JPA, and Spring Rest. Also see:- Most Commonly Asked Java Interview Questions
Spring Boot Core
1. What is Spring Boot?
- Spring Boot is a spring module.
- It provides rapid application development (RAD) with extra support for auto-configuration and embedded application servers (like Tomcat and Jetty).
- It helps us create efficient, fast, standalone applications that we can just run. It removes many configurations and dependencies.
2. Why did you use Spring Boot in your project? Why not spring?
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. Spring Boot helps you accelerate application development.
It looks at the classpath and beans that we have configured, makes reasonable assumptions about what you are missing, and adds those items. With Spring Boot, you can focus more on business features and less on infrastructure.
For all Spring applications, you should start with the Spring Initializr/Starter which offers a fast way to pull in all the dependencies you need for an application and does a lot of the setup for you.
3. What is RAD? How can you achieve RAD using Spring Boot?
RAD (rapid application development) is a modified waterfall model that focuses on developing software quickly. The phases of RAD are as follows:-
- Business Modeling:- The business model is designed for the product to be developed
- Data Modeling:- The data model is designed, The relation between these data objects is established using info gathered in the first phase.
- Process Modeling:- Process model is designed. Process descriptions for adding, deleting, retrieving, or modifying a data object are given.
- Application Generation:- The actual Product is built using coding. Convert process and data models into actual prototypes.
- Testing and Turnover:- The product is tested and if changes are required then the whole process starts again.
4. Is it possible to change the port of the Embedded Tomcat server in Spring Boot?
Yes. By default, it is on port 8080. To change put server.port=8085
properties in the application.properties file.
5. Can we override or replace the embedded Tomcat server in Spring Boot?
Yes. We can replace the embedded tomcat with any other servers by using the starter dependencies like- you can use spring-boot-starter-jetty as a dependency for each project as you need. The spring-boot-starter-web
dependency is responsible for embedding the Tomcat server. To replace the tomcat server with the jetty server, first exclude the tomcat server and then add the jetty server dependency. Replace the above dependency with the below one:-
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
6. Can we disable the default web server in the Spring Boot application?
Yes. Instead of using the embedded server provided by Spring Boot, we can disable the default embedded server and use our own configured server. The major strong point in Spring is to provide flexibility to build your application loosely coupled. Spring provides features to disable the web server in a quick configuration. We can use the application.properties to configure the web application type i.e. spring.main.web-application-type=none
7. How to disable a specific auto-configuration class?
If we find any specific auto-configuration classes that we do not want to use then we can use the exclude attribute of @EnableAutoConfiguration.
@SpringBootApplication
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
We can add multiple classes separating them by comma.
@EnableAutoConfiguration(exclude={A.class, B.class, C.class})
8. What does the @SpringBootApplication annotation do internally?
@SpringBootApplication is a convenience annotation that adds all of the following:-
- @Configuration: Tags the class as a source of bean definitions for the application context.
- @EnableAutoConfiguration: Tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings. For example, if spring-web MVC is on the classpath, this annotation flags the application as a web application and activates key behaviors, such as setting up a DispatcherServlet.
- @ComponentScan: Tells Spring to look for other components, configurations, and services in the com/example package, letting it find the controllers.
9. How to use a property defined in the application.properties file in your Java class?
Use the @Value annotation to access the properties which are defined in the application-properties file.
@Value("${custom.value}")
private String customVal;
10. What is the use of profiles in Spring Boot?
- When developing applications for the enterprise, we typically deal with multiple environments such as Dev, QA, and Prod. The configuration properties for these environments are different.
- For example, we might be using an embedded H2 database for Dev, but Prod could have the proprietary Oracle or DB2. Even if the DBMS is the same across environments, the URLs would be different.
- To make this easy and clean, Spring has the provision of profiles, to help separate the configuration for each environment. So instead of maintaining this programmatically, the properties can be kept in separate files such as application-dev.properties and application-prod.properties. The default application properties point to the currently active profile using spring.profiles.active so that the correct configuration is picked up.
Whichever profile is active in the application.properties file, that file will be picked.

11. What are the steps to deploy Spring Boot web applications as JAR and WAR files?
To deploy a Spring Boot web application, you just have to add the following plugin in the pom.xml file:-
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<build>
By using the above plugin, you will get a JAR executing the package phase. This JAR will contain all the necessary libraries and dependencies required. It will also contain an embedded server. So, you can run the application like an ordinary JAR file.
Note: The packaging element in the pom.xml file must be set to jar to build a JAR file as below:-
<packaging>jar</packaging>
// or
<packaging>war</packaging>
12. What are the advantages of the YAML file over the Properties file?
- More clarity and better readability.
- Perfect for hierarchical configuration data, which is also represented in a better, more readable format
- Support for maps, lists, and scalar types
We don’t need any plugin/configuration or a separate dependency to work with YML files in Spring Boot. In maven dependencies, we can find snakeyml-version.jar file which is responsible for converting data given in YML into the java.util.Properties.
Create a new Spring boot project. In the src/main/resources folder where the application.properties file resides, create another file:- application.yml
In application.yml:-
my:
app:
id: 10
name: abc
cost: 500.0
Create a runner class to read the data and test it:-
package com.knowprogram.demo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Component
@Getter
@Setter
@ToString
public class DataReadRunner implements CommandLineRunner {
@Value("${my.app.id}")
private Integer pid;
@Value("${my.app.name}")
private String name;
@Value("${my.app.cost}")
private Double pcost;
@Override
public void run(String... args) throws Exception {
System.out.println(this);
}
}
Run the application. In console:-
DataReadRunner(pid=10, name=abc, pcost=500.0)
13. Which is given preference Yaml or property file in Spring boot?
Application.properties are given preferences over the application.yml file in the spring boot application.
14. Explain layers in your application.
We can layer/split an application in a client-server architecture as:-
- Presentation Logic
- Business Logic
- Data Source
15. Why do we need controller service DAO separated?
We use programming language like Java to implement Business logic on server. It’s furthermore modularised/divided into:-
- Controller layer
- Business layer
- DAO layer
16. What is IOC in Spring?
In Spring, IOC stands for Inversion of Control. It’s a principle where the control of the flow of a program is shifted from the application code to the framework or container. In the context of Spring Framework, IOC is primarily implemented through Dependency Injection (DI).
Here’s how IOC works in Spring:-
- Dependency Injection (DI): Spring manages the dependencies of a class by injecting them into the class at runtime, rather than the class itself creating its dependencies. This way, the class is not tightly coupled to its dependencies, making it more flexible and easier to maintain.
- Container: Spring IOC container is responsible for managing the application components (beans) and their dependencies. It creates instances of beans, wires them together, configures them, and manages their lifecycle.
- Configuration Metadata: Spring IOC container relies on configuration metadata to understand how to create and wire beans. This metadata can be provided either through XML configuration files, Java-based configuration classes, or annotations.
- Bean Lifecycle Management: Spring IOC container manages the lifecycle of beans, including their creation, initialization, usage, and destruction. Developers can hook into this lifecycle by implementing specific interfaces or using annotations.
- Inversion of Control: With IOC, the flow of control is inverted from the application code to the Spring framework. Instead of the application code directly creating and managing dependencies, Spring takes control and manages the dependencies, allowing for greater flexibility, modularity, and testability.
Overall, IOC in Spring, implemented through Dependency Injection, promotes loose coupling, separation of concerns, and easier unit testing, making the application more modular, maintainable, and extensible.
17. Different ways to achieve the dependency injection?
Dependency Injection (DI) can be achieved in several ways. Here are the most common methods:-
1. Constructor Injection: Dependencies are provided through a class’s constructor. This is one of the most straightforward and widely used methods for DI.
public class MyClass {
private final Dependency dependency;
public MyClass(Dependency dependency) {
this.dependency = dependency;
}
}
2. Setter Injection: Dependencies are provided through setter methods on the class. This approach allows for more flexibility, as dependencies can be changed after the object is constructed.
public class MyClass {
private Dependency dependency;
public void setDependency(Dependency dependency) {
this.dependency = dependency;
}
}
3. Field Injection: Dependencies are injected directly into fields using annotations (like @Autowired in Spring). Simplifies code but can obscure dependencies, making it harder to track them.
public class Service {
@Autowired
private Repository repository;
}
Constructor injection is recommended for mandatory dependencies, while setter injection is more suitable for optional dependencies or when a class has many dependencies.
18. Difference between setter injection and constructor injection?
- Setter Injection: Dependencies are injected after bean creation via setter methods, allowing for changes post-instantiation.
- Constructor Injection: Dependencies are injected at bean creation via the constructor, ensuring immutability and mandatory dependencies.
In short, use setter for flexibility and constructor for required, unchangeable dependencies.
19. What are the different bean scopes?
In Spring Framework, bean scope defines the lifecycle and visibility of a bean instance. Spring supports several bean scopes, each serving different purposes and having different lifecycles. Here are the most commonly used bean scopes:-
- Singleton: In singleton scope, the Spring container creates only one instance of the bean per container. It is the default scope in Spring. This single instance is shared by all clients requesting the bean. It’s suitable for stateless beans or beans that are not thread-safe.
- Prototype: In the prototype scope, a new instance of the bean is created every time it is requested from the container. This means that each client receives a unique instance of the bean. Prototype scoped beans are suitable for stateful beans or beans that require customization for each usage.
- Request: In the request scope, a new instance of the bean is created for each HTTP request. This scope is only available in a web-aware Spring ApplicationContext and is used for beans that are tied to the lifecycle of an HTTP request.
- Session: In session scope, a new instance of the bean is created for each HTTP session. Like the request scope, this scope is only available in a web-aware Spring ApplicationContext and is used for beans that are tied to the lifecycle of an HTTP session.
- Application: In the application scope, a single instance of the bean is created for each ServletContext. This scope is also only available in a web-aware Spring ApplicationContext and is used for beans that are intended to be shared across the entire application.
- WebSocket: In the WebSocket scope, a new instance of the bean is created for each WebSocket session. This scope is specific to WebSocket-based applications and is used for beans that are tied to the lifecycle of a WebSocket session.
These are the most commonly used bean scopes in Spring Framework. Choosing the appropriate scope for a bean depends on factors such as the statefulness of the bean, the requirements of the application, and the desired lifecycle of the bean instance.
20. Advantages of Spring Boot over Spring?
Spring Boot is a framework built on top of the Spring Framework, aiming to simplify the configuration and development of Spring applications. Here are some advantages of Spring Boot over traditional Spring Framework:-
- Auto-configuration: Spring Boot provides auto-configuration, which automatically configures the Spring application based on dependencies and classpath. This reduces the need for manual configuration, making it easier to start and configure Spring applications.
- Standalone applications: Spring Boot allows you to create standalone applications with embedded servers like Tomcat, Jetty, or Undertow. This eliminates the need for deploying applications to external servers, simplifying deployment and reducing overhead.
- Opinionated defaults: Spring Boot comes with opinionated defaults for various libraries and dependencies. It provides sensible defaults for configuration, reducing the need for explicit configuration and enabling developers to focus more on application logic.
- Production-ready features: Spring Boot includes production-ready features such as metrics, health checks, and externalized configuration. These features are essential for building robust and scalable applications and are readily available out of the box.
- Integrated development experience: Spring Boot provides a seamless development experience with tools like Spring Initializr, which allows you to quickly bootstrap Spring projects with desired dependencies and configurations. It also integrates well with other Spring projects and libraries.
- Microservices architecture support: Spring Boot is well-suited for building microservices-based architectures. It provides features like embedded servers, externalized configuration, and easy integration with Spring Cloud for building scalable and resilient microservices.
- Community and ecosystem: Spring Boot has a vibrant community and ecosystem with extensive documentation, tutorials, and community support. It’s backed by the Spring team at Pivotal, ensuring regular updates, bug fixes, and improvements.
Overall, Spring Boot simplifies and accelerates the development of Spring applications by providing auto-configuration, standalone capabilities, opinionated defaults, production-ready features, and seamless integration with other Spring projects. It’s a powerful framework for building modern, scalable, and maintainable Java applications.
21. If you want to exclude some packages from scanning, then how will you do that?
If you want to exclude certain packages from component scanning in a Spring Boot application, you can use the exclude attribute of the @ComponentScan annotation. This attribute allows you to specify the classes or packages to exclude from component scanning.
Here’s how you can use it:-
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(exclude = {"com.example.package1", "com.example.package2"})
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
22. Can we use @Component in place of @Service?
Yes, you can use @Component instead of @Service in Spring Framework. @Component, @Service, @Repository, @Controller, and @RestController are all stereotype annotations in Spring, and they serve similar purposes of indicating that a class is a Spring-managed component. However, they carry some semantic meaning to convey the role of the annotated class within the application:-
- @Component: This is a generic stereotype annotation used for any Spring-managed component. It’s typically used when the class doesn’t fit into more specific stereotype annotations like @Service, @Repository, or @Controller.
- @Service: This annotation is used to indicate that the annotated class is a service component in the business logic layer. It’s often used to mark classes that perform service-oriented tasks, such as processing business logic, interacting with databases, or communicating with external services.
In practice, you can use @Component instead of @Service if you prefer to keep your code more generic and avoid any implications or assumptions about the role of the class within the application. However, using more specific stereotype annotations like @Service, @Repository, and @Controller can provide clearer semantics and better express the purpose of the annotated classes. It also helps with better organization and readability of the codebase, especially in larger projects.
23. What are the stereotype annotations?
@Component, @Service, @Repository, @Controller and @RestController are all stereotype annotations in Spring.
24. Tell annotation which has stereotype annotation inbuilt?
- @RestController
- @ControllerAdvise
- @Configuration
25. Tell 5 spring annotations that you have used excluding the stereotype annotations and excluding annotations that are stereotype embedded.
- @NoRepositoryBean:- It is used when we don’t want to class/interface to be picked up by the container for instantiation.
- @GetMapping/@PutMapping
- @DataJpaTest
- @SpringBootConfiguration
- @Bean
- @Scope
Annotations from Spring AOP:- @Aspect, @Before, @After, @AfterReturning, @AfterThrowing, @Around, @Pointcut, @DeclareParents
Annotations from Spring security:- @EnableWebSecurity, @Secured, @RolesAllowed, @PreAuthorize and @PostAuthorize
26. What spring boot annotations you have used?
- @SpringBootApplication, @EnableWebSecurity.
- Stereotype annotations: @Component, @Cotroller, @RestController, @Service, @Repository.
- At method level: @Bean, @GetMapping, @PostMapping, @RequestMapping, @RequestBody, @Autowired, @Primary, @Qualifier
27. @Autowired vs @Qualifier?
@Autowired
- Purpose: Automatically injects dependencies by type.
- Usage: Declares dependencies in your class and lets Spring resolve and inject them based on type.
- Example:
@Autowired
private MyService myService;
Where MyService is given as:-
@Configuration
public class AppConfig {
@Bean
@Primary
public MyService primaryService() {
return new PrimaryService();
}
@Bean
public MyService secondaryService() {
return new SecondaryService();
}
}
@Qualifier
- Purpose: Specifically identifies which bean to inject when multiple candidates are available.
- Usage: Used in conjunction with
@Autowired
to resolve ambiguity by specifying the exact bean name. - Example:-
@Autowired
@Qualifier("secondaryService")
private MyService myService;
In short, @Autowired injects by type, while @Qualifier specifies the exact bean to inject when there’s more than one candidate.
28. What is the purpose of @Primary?
It is used to indicate a primary bean among multiple candidates that match a particular type. When multiple beans are qualified for autowiring, @Primary
gives preference to the annotated bean.
@Configuration
public class AppConfig {
@Bean
@Primary
public MyService primaryService() {
return new PrimaryService();
}
@Bean
public MyService secondaryService() {
return new SecondaryService();
}
}
In this example, primaryService
is marked as the primary bean, so it will be autowired preferentially when MyService
is required.
Spring Data JPA
1. Do we need to write @Repository annotations when using Spring Data JPA annotations?
@Repository
//Is using the above annotation required?
public interface SongRepository extends JpaRepository<Song, Integer> { }
No, it is not required. Springboot automatically detects the Spring Data JPA-related classes/interfaces. Our interface is already extending to the Spring Data JPA therefore it is not necessary to write @Repositry on top of our interface.
Even though we are writing @Reposity on top of our interface but the implementation classes are generated by the Spring boot framework with all CRUD features.
2. Difference between JpaRepository, CrudRepository, PagingAndSortingReposity. Tell the hierarchy.
The Base is the Repository interface which is a marker interface.
@Indexed
public interface Repository<T, ID> {
}
The next layer is CrudRepository & PagingAndSortingRepository, both extending from the Repository marker interface. CrudRepository has all the CRUD-related methods like findAll, findAllById, findById, save, delete, and e.t.c.
@NoRepositoryBean
public interface CrudRepository<T, ID> extends Repository<T, ID> {
}
The PagingAndSortingRepository contains methods related to sorting and pagination.
@NoRepositoryBean
public interface PagingAndSortingRepository<T, ID> extends Repository<T, ID> {
}
The next layer is JpaRepository which contains methods like flush(), saveAndFlush(), deleteAllInBatch(), deleteAllByIdInBatch().
@NoRepositoryBean
public interface JpaRepository<T, ID> extends ListCrudRepository<T, ID>, ListPagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {
}
3. What is the default JPA provider for the Spring Data JPA?
Hibernate.
4. Why CrudRepository, PagingAndSortingRepository, JpaRepository have @NoRepositoryBean. Can we use it in our interfaces extending from these classes?
Yes, we can add @NoRepositoryBean into our interfaces which extend from these repositories (like JPARepositories). When we add @NoRepositoryBean then Spring will not instantiate that interface.
When @NoRepository is used? If we don’t want to initialize an interface or we don’t want to create an object for that interface because at runtime spring only gives the interface implementation, so if we don’t want spring to create an implementation for that we don’t want to initialize the interface
Example:- I have my own interface that implements/extends from JPARepository or CrudRepository then why to create the object for JPArepository/CrudRepository? We should directly create object for our own interface. If my interface also has another child class let’s say we are inheriting some property from our parent class so we should use @NoRepository on top of our parent interface so that only spring will instantiate the child interface.
5. Tell me a little about the Spring Data JPA project.
Normally if we create any project that has some relationship with the database we create the interface and we give the implementation class of that interface and try to connect up with the database. For example, if we say a raw JDBC application or even spring JDBC we write the queries we open data source, create connection, perform actions like fetching/saving the data, and then we close the connection making the transaction to be done safely.
But in Spring Data it is a layer in between the provider implementation and the database.
Layers:- Spring Data JPA layer => JPA provider layer (Hibernate) => Database layer.
So Spring Data JPA gives data initialization and utility methods for our entities. It executes the query with the help of the JPA provider. With the help of auto-configuration, it creates the EntityManager basically the session of the persistence context, and also creates the EntityManagerFactory with the help of data source details given in the configuration. It takes care of the transactions as well.
We extend one repository called the JPA repository with the help of that we can create our own functions.
Note:- All the JPA method implementation will be given by Hibernate if you are using Spring Data JPA.
Spring Data is an abstraction for any database that wants to connect to the application. Spring Data contains the base repositories:-
- Repository
- CrudRepository
- PagingAndSortingRepository
- If we use spring-data-jpa then JpaRepository will come.
- If we use spring-data-mongodb then MongoRepository will come.
- If we use spring-data-redis then RedisTemplate will come.
Spring Rest
1. Explain @RestController annotation in Spring Boot.
- @RestController is a convenience annotation for creating Restful controllers. It is a specialization of @Component and is auto-detected through classpath scanning.
- It adds the @Controller and @ResponseBody annotations. It converts the response to JSON or XML which eliminates the need to annotate every request-handling method of the controller class with the @ResponseBody annotation. It is typically used in combination with annotated handler methods based on the @RequestMapping annotation.
- It indicates that the data returned by each method will be written straight into the response body instead of rending a template.
2. Difference between @RestController and @Controller in Spring Boot?
Let us first understand the difference between a web application and a REST API:-
- Response from a web application is generally a view (HTML + CSS + JavaScript) because they are intended for human viewers while REST API just returns data in the form of JSON or XML because most of the REST clients are programs.
- The same goes for @RestController and @Controller annotation.
- @Controller Map of the model object to view or template and makes it human readable but @RestController simply returns the object and object data is directly written into HTTP response as JSON or XML.
3. What are the major differences between @RequestMapping and @GetMapping?
@RequestMapping can be used with GET, POST, PUT, and other request methods using the method attribute on the annotation. Whereas @GetMapping is only an extension of RequestMapping, which helps us to improve clarity on requests.
Spring Actuator
1. What is the Spring Actuator? What are its advantages?
- Actuator is a manufacturing term that refers to a mechanical device used to move or control something. Actuators can generate a large amount of motion from a small change.
- In Spring Boot, Actuator is an additional feature that helps us monitor and manage the application when we push it to production. These features include Auditing, health, metrics gathering, and many more features that can be automatically applied to the application.
- You can enable this feature by adding the dependency:
spring-boot-starter-actuator
in pom.xml - Using Spring Actuator, you can access those flows like what bean is created, CPU usage, and HTTP hits your server has handled.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2. What are different Actuator Endpoints?
By Default Exposed endpoints can be seen at:- http://localhost:8080/actuator. To explicitly include/expose all endpoints use this in the properties file:- management.endpoints.web.exposure.include=*
To expose only selected endpoints:- management.endpoints.jmx.exposure.include=health,info,env,beans
To get environmental configuration about the server:- http://localhost:8080/actuator/env
To get all the spring beans loaded in the context:- http://localhost:8080/actuator/beans
Different endpoints when we expose all endpoints:-

3. How to modify the actuator endpoint path.
By default, all endpoints come in the default context path of the application, suffixed with /actuator. If for some reason, we have existing endpoints in the application starting with /actuator, then we can customize the base path to something else.
management.endpoints.web.base-path=/manage
Now we will be able to access all actuator endpoints under a new URL. e.g:- /manage/health
4. Customize the management server port.
We can also change the port of the actuator. The application will be running on different ports and the actuator will be running on another.
management.server.port=8090
5. How to create custom Endpoints for the Actuator?
This can be achieved by adding the following annotations:-
- Add @Endpoint and @Component to class
- Add @ReadOperation, @WriteOperation, or @DeleteOperation on method level
- @ReadOperation maps to HTTP GET
- @WriteOperation maps to HTTP POST
- @DeleteOperation maps to HTTP DELETE
By adding bean annotated with @Endpoint, any methods annotated with @ReadOperation. @WriteOperation or @DeleteOperation are automatically exposed over JMX or HTTP.
package com.example.demo;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;
@Component
@Endpoint(id = "customActuator")
public class CustomActuator {
@ReadOperation
public String currentDbDetails() {
return "Give current DB status of the application";
}
}

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!