Spring / Spring Boot
1. What is Spring Boot?
Spring Boot is a framework for building and running Spring applications by providing defaults for code and annotation configuration to quick start new Spring projects within no time. It follows "Opinionated Defaults Configuration" Approach to avoid lot of boilerplate code and configuration to imp...
2. Advantages of using Spring Boot.
To ease the Java-based applications Development, Unit Test and Integration Test Process. To reduce development, unit Test and integration Test time by providing some defaults. To increase productivity. It avoids writing lots of boilerplate code, annotations and XML configuration. It is very easy ...
3. What are the limitations of Spring Boot?
We can convert all kinds of spring projects into Spring Boot Applications however it is time consuming process to convert existing or legacy Spring Framework projects into Spring Boot Applications.
4. Can we use spring boot for applications that are not built using Spring framework?
No. Spring Boot is limited to work with Spring based applications (Java/groovy).
5. What is the latest version of Spring Boot?
2.2.1 is the latest version.
6. Explain CommandLineRunner interface in Spring boot.
CommandLineRunner Interface is used to indicate that a bean should run when it is contained within a Spring application. Multiple CommandLineRunner beans can be defined within the same application context and can be ordered using the Ordered interface or @Order annotation.
7. Difference between CommandLineRunner and ApplicationRunner in Spring Boot.
Both are similar in terms of functionality and the difference is that If you need access to ApplicationArguments instead of the raw String array consider using ApplicationRunner than CommandLineRunner.
8. What are microservices?
Micro service is an architectural style that structures an application as a collection of loosely coupled services, which implement business capabilities. The microservice architecture enables the continuous delivery/deployment of large, complex applications. It also enables an organization to ev...
9. What are the components of Spring Boot?
The components are, Spring Boot Starter, Spring Boot AutoConfigurator, Spring Boot Actuator, Spring Boot CLI, Spring Boot IDE, and Spring Boot Initilizr.
10. What is name of the configuration file that you use in Spring boot?
Configuration file used in Spring boot projects is application.properties. It is used to override all default configurations.
11. What is actuator in Spring boot?
Spring boot actuator is one of the important features of Spring boot. It is used to access the current state of running applications in a production environment. There are various metrics that you can use to check the current state of the application. Spring boot actuator provides restful web ser...
12. What are the embedded containers supported by Spring Boot?
Spring boot supports embedded containers such as Tomcat (default), Jetty and undertow servers.
13. Explain spring boot initializr.
Spring Boot Initializr is a Spring Boot tool to bootstrap Spring Boot or Spring Applications easily. Spring Boot Initializr is available in the below forms: Spring Boot Initializr With Web Interface, Spring Boot Initializr With IDEs/IDE Plugins, Spring Boot Initializr With Spring Boot CLI, Spring...
14. How to write Test cases using Spring Boot?
Spring Boot provides the @SpringBootTest annotation for writing Unit Test Cases.
15. How do I change the port of Embedded Server in Spring boot Application?
You may change the port in spring boot by adding a property server.port =
16. Explain Spring boot starters.
Spring Boot Starters are a set of convenient dependency descriptors that you can include in your application. You get all the Spring and related technology at one-stop-shop that you need without having to deal with sample code and copy paste loads of dependency descriptors. It minimizes the effor...
17. Mention some of the Spring Boot starters.
spring-boot-starter-data-jpa for Spring Data JPA. spring-boot-starter-web for Spring Web applcation and creating Restful services. spring-boot-starter-security for Spring security. spring-boot-starter-test for unit testing your application. spring-boot-starter-batch for creating spring batch jobs...
18. Disadvantages of Spring Boot.
Spring boot may include dependencies that are not used thereby causing huge deployment file size. Turning legacy spring applications into Spring boot requires a lot of effort and a time-consuming process. Limited control of your application.
19. How to create an ActiveMQ Spring Boot Application?
Use Spring boot starter spring-boot-starter-activemq dependency in your applcation POM xml file and it takes care of all dependencies and configuration required for activeMQ projects. Under application.properties add a property spring.activemq.broker-url along with the URL to configure external A...
20. How do you reload Spring Boot changes without restarting the server?
Using Spring Boot Dev Tools module we can achieve auto reload. It is a powerful tool that helps developers to lessen the development cycle and enable easy deployment and testing during development. To enable this feature, add the below dependency to Maven POM file.
21. How to customize a banner printed during spring boot app start up?
The banner that is printed on start up can be changed by adding a banner.txt file to your classpath or by setting the spring.banner.location property to the location. In addition to a text file, you can also add a banner.gif, banner.jpg, or banner.png image file to your classpath or set the sprin...
22. How do you upgrade from an earlier version of Spring boot?
When upgrading Spring boot, some properties may have been renamed or removed. Spring Boot provides a way to analyze your application's environment and print diagnostics at startup, but also temporarily migrate properties at runtime. To enable that feature, add the following dependency to your pro...
23. How to create an executable jar for your spring boot application using Maven?
To create an executable jar, add the spring-boot-maven-plugin to our pom.xml. Insert the following lines just below the dependencies section in your project's POM.xml:
24. Can you get spring boot working with ant-based projects?
It is possible to get Spring Boot to work with other build systems such as Ant, but they are not well supported. It is recommended to use with Gradle or Maven.
25. How do I change from tomcat to other embedded containers?
Tomcat is the default embedded container when we specify web since spring-boot-starter-web dependency declares spring-boot-starter-tomcat as its dependency. To change from tomcat to Jetty, we need to remove tomcat dependency by specifying the exclusion in pom.xml if you are using maven.
26. How do I change tomcat port in my spring boot application?
The default tomcat port is 8080. To change it, specify the server.port property with desired port in the application properties or yaml. application.properties: server.port=8091 application.yml: server: port: 8091 Alternatively, you may pass the property as JVM option as -Dserver.port=8091 .
27. What is the role of @SpringBootApplication annotation?
@SpringBootApplication annotation can be used to enable those three features below. @EnableAutoConfiguration enable Spring Boot's auto-configuration mechanism. @ComponentScan enable @Component scan on the package where the application is located. @Configuration allow to register extra beans in th...
28. Can you run Spring boot application using Maven plugin?
Yes, the Spring Boot Maven plugin includes a run goal that is used to quickly compile and run your application. mvn spring-boot:run Similarly, Spring Boot Gradle plugin also includes a bootRun task that can be used to run your application gradle bootRun
29. Advantages of using Spring boot developer tools.
Property Defaults : spring-boot-devtools module automatically applies sensible development-time configuration by disabling properties such as caching to false during development; Sets DEBUG mode for web logging group which helps get more information about incoming request. Automatic Restart : App...
30. What is auto-configuration in Spring boot?
Spring boot automatically configures a lot of dependencies just by its availability in the classpath. For example, it can auto configure tomcat if the server container is not available. This is why spring boot is opinionated because it auto-configure many dependencies if it is not needed and we c...
31. Why do we need starter dependencies in spring boot?
Starter dependencies combine many libraries into one based on its functionality/dependency and acts as a single starter package. It eliminates the need to manually add dependencies in build script and also manages compatibility and version mismatch issues.
32. What are the application events sent by SpringApplication?
An ApplicationStartingEvent is sent at the start of a run but before any processing, except for the registration of listeners and initializers. An ApplicationEnvironmentPreparedEvent is sent when the Environment to be used in the context is known but before the context is created. An ApplicationP...
33. What is thymeleaf?
Thymeleaf is a server-side Java template engine for web applications to bring elegant natural templates for your web apps. It is easy to integrate with spring Framework and works well with HTML5 Java-based web applications. In order to use thymeleaf in your project, add the dependency in your pro...
34. How does the Devtool provided Auto-restart works in Spring Boot?
The Spring Boot restart technology works by using 2 classloaders. Class that don't change ( 3rd party jars, as an example) are loaded into base classloader. Classes that actively change during development are loaded into restart classloader. When the application restarts, the restart classloader ...
35. What is WebApplicationType in Spring Boot?
WebApplicationType is an enumeration that represent possible types of web application. NONE : The application is NOT an web application and should not start an embedded web server. REACTIVE : The application should run as a reactive web application and should start an embedded reactive web server...
36. Difference between CommandLineRunner and ApplicationRunner in Spring Boot?
Both interfaces, CommandLineRunner and ApplicationRunner works in the same way and offers a single run method. The difference is, the CommandLineRunner interface provides access to the application arguments as a simple String array , while ApplcationRunner uses the ApplicationArguments interface,...
37. Why do we need EnvironmentPostProcessor in Spring Boot?
The EnvironmentPostProcessor interface allows us to manipulate the Environment before even the application starts. This interface allows us to create support for encrypting/decrypting property values/ add new properties etc.
38. Default logging system of Spring Boot.
Spring Boot uses commons-logging and LogBack implementation by default.
39. Why spring boot is "opinionated"?
This question is already answered here.
40. How to enable auto-reload of applications on changes in Spring Boot?
You may enable auto-reload of spring boot application by adding the spring-boot-devtools dependency in the pom.xml file.
41. What is the HATEOAS Rest service?
As per wikipedia, Hypermedia as the Engine of Application State (HATEOAS) is a component of the REST application architecture that distinguishes it from other network application architectures. With HATEOAS, a client interacts with a network application which provide information dynamically throu...
42. Explain spring profiles.
Spring Profiles provide a way to segregate parts of your application configuration and make it be available only in certain environments. For example, swagger may be enabled only for lower environments and can be disabled for the production environment. @Configuration @EnableSwagger2 @Profile ( "...
43. How do I configure data source using Spring boot?
Include starter dependencies spring-boot-starter-jdbc or spring-boot-starterdata-jpa and include a JDBC driver on classpath. Spring boot will configure the database with the properties defined in application.properties. spring.datasource.url=jdbc:mysql://localhost:2001/mydb spring.datasource.user...
44. How do I implement security in spring boot?
Configure Spring Security in the application. If Spring Security is on the classpath, then Spring Boot automatically secures all HTTP endpoints with "basic" authentication. dependencies { ... compile("org.springframework. boot:spring-boot-starter-security " ) ... } Add the security configuration ...
45. What is Swagger and how do I implement it with Spring Boot?
Swagger UI enables users to visualize and interact with the API's resources without having any of the implementation logic in place. It is automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation ...
46. How to disable specific auto-configuration in spring boot?
Use exclude property to disable specific auto-configuration. @EnableAutoConfiguration (exclude = {DataSourceAutoConfiguration . class})
47. What is Hot swapping in spring boot?
Reloading the changes without restarting the server is called hot swapping, Modern IDEs such as Eclipse, Intellij IDEA support hot-swapping of byte-code, so if you make a change that doesn't affect the class or method signatures it should reload cleanly with no side effects.
48. How do I write a JSON REST service in spring boot?
Any Spring @RestController in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath.
49. How to enable HTTP response compression in spring boot?
HTTP response compression is supported by Jetty, Tomcat, and Undertow embedded containers. It can be enabled by adding server.compression.enabled=true in application.properties.
50. How spring-boot handle the error in the application?
Spring Boot provides error mapping by default that handles all errors in a sensible way, and it is registered as a 'global' error page in the servlet container.
51. Default Multipart File Uploads size in spring boot.
Spring Boot configures Spring MVC with a maximum file of 1MB per file and a maximum of 10MB of file data in a single request.
52. What is spring-boot-starter-data-jpa?
Spring Boot provides spring-boot-starter-data-jpa, which is one of the Spring Boot Starters, to easily connect relational database with Spring MVC applications.
53. How to exclude any package in Spring boot from the component scan?
You may use the exclude attribute with the annotation @SpringBootApplication. @SpringBootApplication (exclude = {Employee . class}) public class AppConfiguration {}
54. How do I ensure my spring boot application is secured?
IP whitelisting restricts access from unauthorized resource. Run service endpoints in HTTPS in PROD environment. Enable CSRF tokens. Prevent XSS attacks by using content security policies. Always upgrade to the latest versions of dependencies. Use vulnerability monitoring tools such as snyk. Don'...
55. Difference between Mono and Flux In reactive programming.
Mono and Flux are both reactive streams. A Mono is a stream of 0 to 1 element, whereas a Flux is a stream of 0 to N elements.
56. What is spring boot admin?
Spring Boot Admin is a community project from codecentric. Spring boot admin helps manage and monitor your Spring Boot applications. The spring boot apps register with Spring Boot Admin Client (through HTTP) or discovered using Spring Cloud (for example, Eureka, Consul). The UI is just a Vue.js a...
57. What is HttpMessageConverter?
HttpMessageConverter is a strategy interface that specifies a converter that can convert from and to HTTP requests and responses. By default, the following HttpMessageConverters are loaded by Spring. ByteArrayHttpMessageConverter that can read and write byte arrays. ResourceHttpMessageConverter c...
58. What is Apache Tomcat?
Apache Tomcat is a Web Server and Servlet system which is open source (freely available on the internet). It is created by Apache Software Foundation. Apache Tomcat is required to run Java Web Applications on the host and server based system. It runs JSP and Servlets within its web container.
59. What is CATALINA in Apache tomcat?
Catalina is the inbuilt web container of Apache tomcat. It can be located in bin directory. Catalina loads all the HTTP requests and instantiate the objects of GET and POST methods.
60. Difference between an embedded container and a WAR.
Embedded container let Spring Boot application run as a JAR directly from the command prompt without setting up a web server. Embedded container auto configure web server and run the application. But to run a WAR file, you need to first set up a web server like Tomcat which has Servlet container ...
61. How do you control logging with Spring Boot?
Spring boot can control logging by specifying log levels on application.properties file. Spring Boot uses Commons Logging for all internal logging and you can change log levels by adding following lines in the application.properties file. logging.level.org.springframework.web=ERROR logging.level....
62. Explain Spring Boot Maven Plugin, its advantages and the goals/commands that it provides.
The Spring Boot Maven Plugin provides Spring Boot support in Maven, packages executable jar or war archives and run an application "in-place". The Spring Boot Plugin has the following goals. spring-boot:run runs/executes your Spring Boot application. spring-boot:repackage repackages your jar/war ...
63. The default number of request processing threads in TOMCAT.
Default is 200 threads. The property is maxThreads .
64. What does the "beans" endpoint of Spring boot actuator do?
"beans" endpoint displays a complete list of all the Spring beans in your application.
65. Differences between the Spring framework and Spring boot.
Spring. Spring Boot. Spring framework provides comprehensive infrastructure support for developing Java applications.. Spring Boot is an extension of the Spring framework which eliminated the boilerplate configurations required for setting up a Spring application.. Spring takes an unopinionated v...
66. Spring boot default JPA provider.
Hibernate.
67. What is relaxed binding in Spring boot?
Relaxed binding maps the Environment property to the bean property name even it is not an exact match. For example, dash-separated environment properties (app-name bound to appName) or capitalized properties as in PORT (bound to port). Spring boot supports relaxed binding. @Component @Configurati...
68. What is Spring profile?
Spring profiles provide a way to segregate parts of your application configuration, allows logical grouping of configurations based on environment and make it be available only in certain environments. Spring Boot by default, creates the property file, application.properties . To create spring pr...
69. Difference between @EnableAutoConfiguration and @SpringBootApplication.
@SpringBootApplication. @EnableAutoConfiguration. @SpringBootApplication allows you to run the Main class as a JAR with an embedded container. It enables Java configuration, and it also enables Component Scanning. @EnableAutoConfiguration enables automatic configuration features of the Spring Boo...
70. Why do we need spring-boot-maven-plugin?
Spring Boot Maven Plugin plugin provides several goals to work with a Spring Boot application: Creates a jar or war file that is auto-executable, runs your Spring Boot application, integrate your Spring Boot application to the integration-test phase so that the application starts before it. gener...
71. How to access value for config from application.properties file in Spring Boot?
@Value annotation can be used to access the property defined in the application.properties. @Value also can set a default value to use if the property is missing in the application.properties. @Value ( "${host.name}" ) private String hostName; Using default value, @Value ( "${host.name:default-ho...
72. How to Lazily initialize your spring boot application?
SpringApplication allows an application to be initialized lazily. When lazy initialization is enabled, beans are created as they are needed rather than during application startup. This reduces the startup time and especially in web apps, the bean is not loaded until an HTTP request is received. s...
73. Is it possible to use XML configurations with Spring Boot?
Yes. Spring Boot supports XML based configuration although it supports Java-based configuration. To load XML configurations, create a @Configuration class and use @ImportResource annotation to load XML configuration files.
74. How do you configure JMS (for example, ActiveMQ) in your spring boot application?
Spring boot has a starter for ActiveMQ known as "spring-boot-starter-activemq" can be added in your project build configuration as a dependency that provides default settings. To configure your external ActiveMQ Broker, configure the ActiveMQ broker URL details in the spring.activemq.broker-url c...
75. How to enable HTTP response compression in spring boot?
Most of the embedded servers and external servers support HTTP compression. It can be enabled by adding server.compression.enabled=true in application.properties.
76. Mention some of the important Spring Boot Actuator Endpoints.
Endpoints. Details. env This endpoint exposes properties from Spring Configurable environment. health Displays the health information of application. shutdown Allows the application to shutdown gracefully. auditevents exposes all audit event for the application. metrics displays "metrics" informa...
77. How do you disable a specific auto-configuration class in Spring boot?
Use exclude attribute of @EnableAutoConfiguration to specific auto-configuration classes that you do not want being auto-configured. @EnableAutoConfiguration (exclude = {DataSourceAutoConfiguration . class,SecurityAutoConfiguration . class}) if the class is not on the classpath, use the excludeNa...
78. Where do I store static content in Spring Boot?
Spring boot automatically maps / src/main/resources/static as static resource folder. To add css or js, create subdirectories like /src/main/resources/static/css/ and /src/main/resources/static/js.
79. How do you implement Spring batch in Spring boot?
Batch processing involves the processing of large volumes of data. Spring boot batch provides reusable components, provides services and features for optimization and partition techniques, resulting in high volume and high-performance batch jobs. Use spring-boot-starter-batch to implement batch p...
80. What is the purpose of io.spring.dependency-management plugin in Spring Boot?
io.spring.dependency-management gradle plugin provides Maven-like dependency management functionality. buildscript { repositories { maven { url ' https: // repo . spring . io / plugins-snapshot ' } } dependencies { classpath ' io . spring . gradle : dependency-management-plugin : 1.0.7 . BUILD-SN...
81. How to enable SSL (HTTPS) support for a Spring Boot web application?
To enable SSL or HTTPS for your Spring Boot web application, place the certificate ( .p12 or .jks extension) under the resources folder, and define the server.ssl.* configuration in the application.properties. server.port=8443 server.ssl.enabled=true server.ssl.key-alias=tomcatApp-localhost serve...
82. Explain @ConditionalOnBean annotation.
@ConditionalOnBean annotation can be used to declare a condition. Only if the specified condition is satisfied then only bean will be added to the application context.
83. Does @Value annotation support relaxed binding?
No.
84. Difference between @ConfigurationProperties and @Value.
@ConfigurationProperties support Relaxed binding & Metadata features while @Value doesn't. @Value support SpEL evaluation while @ConfigurationProperties doesn't.
85. What is Spring Boot Starter Parent?
The "spring-boot-starter-parent" is a special starter that provides useful Maven defaults. It provides default configurations to your application and also the complete dependency tree to quickly build your Spring Boot project. Default java version is 1.6. you may override this by specifying a pro...
86. How ApplicationContext is initialized in Spring boot?
ApplicationContext is the core interface, represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans. ApplicationContext is responsible for bean factory methods for accessing application components, loading file resources, internalization, etc....
87. How Spring Boot Application works internally?
The application starts using the "main method" which calls the "run" method. From the run method, the main application context kicks off which searches for the classes annotated with @Configuration and initializes all the declared beans in those configuration classes. Based on the scope of those ...
88. How to generate Build Information in your Spring boot application?
Both the Maven plugin and the Gradle plugin allow generating build information containing the coordinates, name, and version of the project. build-info goal, as shown in the following example:
89. What are the spring boot actuator endpoints enabled by default?
info and health are enabled by default. All others need to be enabled using configuration.
90. What is JSON Web Token (JWT)?
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way of securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. The client will need to authenticate with the serve...
91. Explain the Spring MVC Auto-configuration features by Spring Boot.
Spring Boot provides the following auto-configuration features for Spring MVC that works well with most applications. Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans. Support for serving static resources , including support for WebJars. Automatic registration of Convert...
92. How do you convert JSON HTTP request to Java and create XML response in Spring boot?
With Inbuilt Http Message conversion, we may implement minimal changes. @PostMapping (path = "/mapJsontoXML" , consumes = MediaType . APPLICATION_JSON_VALUE, produces = MediaType . APPLICATION_XML_VALUE) public @ResponseBody RequestModel mapJsonToXML( @RequestBody final RequestModel request) { re...
93. How do I enable "beans" actuator endpoint in Spring boot?
"beans" endpoint is not enabled by default as it exposes certain sensitive information. However, for troubleshooting purposes, we can enable by configuration management.endpoints.web.exposure.include property in application.properties file or application.yaml. management.endpoints.web.exposure.in...
94. Explain how to find the process uptime using Actuator endpoint in Spring boot.
We may use "metrics" actuator endpoint. Spring Boot provides "metrics" endpoint that can be used diagnostically to examine the metrics collected by an application. The endpoint is not available by default and must be exposed. management.endpoints.web.exposure.include=info,health,metrics When the ...
95. How do I change the filename of application.properties in Spring boot?
Rename tne application.properties as required, for example, ConverterProj.properties and specify the JVM parameter -Dspring.config.name=ConverterProj so that the properties loads from the properties file.
96. How do you hide passwords in Spring boot application properties file?
Spring Boot Application properties may contain sensitive information such as database passwords, MQ config details, CERT passwords. The password stored in the application properties is not recommended to be PLAIN-TEXT and needs to be encrypted. #Plain password not recommended app.mysql.password=M...
97. What does the spring annotation @ConditionalOnMissingBean used for?
The @ConditionalOnMissingBean annotation is a spring conditional annotation for registering beans only when they are not already in the application context. @Bean @ConditionalOnMissingBean (SomeBean . class) public SomeBean otherBean(){ return new SomeBean(); } The above bean will get loaded by S...
98. How to implement exception handling using Spring Boot?
Spring provides an easy way to handle exceptions using ControllerAdvice annotation. We handle all exceptions thrown by the controller class by implementing a ControlerAdvice class. Spring 3.2 brings support for a global @ExceptionHandler with the @ControllerAdvice annotation that enables a mechan...
99. How do I create XML based REST API using Spring Boot?
Add Jackson XML extension (Jackson-dataformat-XML) on the classpath, it will be used to render XML responses.
100. What is @ImportResource annotation in Spring/Spring boot?
The @ImportResource annotation is used to import one or more XML configuration files containing bean definitions.
101. How to run spring boot application in Docker?
We can run Spring Boot inside docker by defining "Docker image" using Dockerfiles. Dockerfiles are a manifest of commands used to build and configure our docker container. To configure our Docker image to run our Spring Boot application, we will want to: Install latest CentOS (OS) image from Dock...
102. Explain Cloud Foundry.
Cloud Foundry is a PaaS (Platform as a Service) service where we can easily deploy and manage our spring/spring boot applications and the Cloud Foundry will take care of the rest of the cloud-based features like scalability, high availability, etc.
103. Explain about Spring Boot testing features.
Spring Boot provides a number of utilities and annotations to help to test your application. Use the spring-boot-starter-test "Starter", which imports both Spring Boot test modules (spring-boot-test and spring-boot-test-autoconfigure) as well as other below libraries. spring-boot-test, a spring b...
104. What is CORS in Spring Boot?
CORS (Cross-Origin Resource Sharing) is a mechanism implemented by browsers and helps users to authorize cross-domain requests. This mechanism serves as an alternative to less secure and less powerful hacks of the kinds of IFrame or JSONP.
105. What is Spring Boot Starter for the SOAP web service?
To create SOAP web service, we need spring-boot-starter-web-services as following.
106. What is Response Entity object in Spring Boot?
Response Entity is an HTTP response object that includes headers,status code and payload/body of your response.
107. What are the components of a Blockchain ecosystem?
There are 4 primary components of a Blockchain ecosystem: Node application, Shared ledger, Consensus algorithm, and Virtual Machine.
108. How is CORS enabled in Spring Boot?
Spring Boot Framework supports CORS and offers different ways to configure. Global CORS configuration: When a global CORS configuration needs to be defined with annotation-based, fine-grained configurations, then the same has to be declared in Spring MVC and combined with @CrossOrigin configurati...
109. What is docker?
Docker is a software platform for building applications based on containers, small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another. Docker is an open source project launched in 2013.
110. What is the use of Docker in spring boot?
Docker enables you to deploy a server environment in containers. A container is a unit of software that assembles code, provide runtime, inject dependencies, configure settings, and initialize the entire app in a single package that you can run reliably from one computing environment to another. ...
111. Advantages of using Spring Boot for creating microservices.
Spring boot provides, single, independent executable JAR packaging with required dependencies. production-ready services for building microservices. actuator, that facilitates health check of the application and monitoring. embedded, pre-configured servers like tomcat. less development effort. mi...
112. How do you register a custom auto-configuration in Spring boot?
To register an auto-configuration class, you must have its fully-qualified name listed under the EnableAutoConfiguration key in the META-INF/spring.factories file: org.springframework.boot.autoconfigure.EnableAutoConfiguration=net.javapedia.autoconfigure.CustomAutoConfigurationExample
113. How to Write Integration Tests for Spring boot applications?
When running integration tests for a Spring application, we must have an ApplicationContext. Spring Boot provides a special annotation for testing @SpringBootTest . This annotation creates an ApplicationContext from configuration classes indicated by its classes attribute. Spring Boot searches fo...
114. What is a shutdown endpoint in the actuator?
Shutdown is an endpoint that allows the application to be gracefully shutdown. This feature is not enabled by default. You may enable this by using management.endpoint.shutdown.enabled=true in your application.properties file.
115. How to disable the default web server in the Spring Boot web application?
We can use the application.properties to configure the web application type to disable web server. spring.main.web-application-type=none
116. What is @Profile annotation in Spring?
Spring @Profile allow developers to register beans by condition. For example, register beans based on what operating system (Windows, Linux/Unix) your application is running, or load database properties file based on the application running in development, test, staging or production environment....
117. How does Spring Boot handle data validation?
In Spring Boot, data validation can be performed using various mechanisms. One common approach is to use the validation annotations provided by the Bean Validation API, such as @NotNull, @Size, and @Pattern , on the fields of model objects. By including the necessary validation annotations, Sprin...
118. What is @TransactionalEventListener annotation in Spring Boot?
The @TransactionalEventListener annotation in Spring Boot lets you listen to transactional events and perform actions based on those events . You can use this annotation on methods that should be invoked when a specific transactional event occurs such as before or after a transaction is committed...
119. What is @ModelAttribute annotation in Spring Boot?
The @ModelAttribute annotation is used in Spring Boot to bind request parameters or form data to method parameters or model attributes. It can be applied to method parameters or method return values. When applied to method parameters, the @ModelAttribute annotation binds the incoming request para...
120. How to change log levels without restart using spring boot actuator?
You can change log levels in a running Spring Boot application without a restart using the Spring Boot Actuator's /actuator/loggers endpoint. This allows you to dynamically view and modify logging configurations via a simple HTTP request. Steps to Implement and Use Dynamic Logging 1. Add the Actu...
121. Difference between HttpServletRequest and ServerHttpRequest.
HttpServletRequest is part of the standard Java Servlet API, designed for use in traditional, thread-per-request servlet containers. ServerHttpRequest is an abstraction introduced by the Spring Framework, primarily for use in reactive programming environments (like Spring WebFlux), which is not t...