Nothing Special   »   [go: up one dir, main page]

Spring Boot Interview Questions For 5+ Years Experience

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

 

Q.How to connect to an external database like MSSQL or oracle with


Spring boot?
It is done in the following steps.

Step 1 -

The first step to connect the database like Oracle or MySql is adding the dependency for your database
connector to pom.xml.

Step 2 -

The next step is the elimination of H2 Dependency from pom.xml

Step 3 -

Step 3 includes the schema and table to establish your database.

Step 4 -

The next step is configuring of the database by using Configure application.properties to connect to your
database.

Step 5-

And the last step is to restart your device and your connection is ready to use.

Q.How to add custom JS code in Spring Boot?


/src/main/resources/static is the suggested folder for static content in Spring boot.

You can create a JS file for sending an alert by creating a custom file named custom.js in
/src/main/resources/static/js/ directory with below code

alert("I'm active");

Q.How can you enable auto reload of application with Spring Boot?
You can enable auto-reload/LiveReload of spring boot application by adding the spring-boot-
devtools dependency in the pom.xml file.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true
</dependency>
Note: please restart your application for immediate effects.
Q.What is the reason to have a spring-boot-maven module?

The reason behind to have Spring-boot-maven module is it gives a couple of charges which empower you to
package the code as a container or run the application

 spring-boot: run operates your Spring Boot application.


 spring-boot: repackage it repackages your jug/war to be executable.
 spring-boot: start and spring-boot: stop to deal with the lifecycle of your Spring Boot application (i.e., for
joining tests).
 spring-boot: build-data creates build data that can be utilized by the Actuator.

Q.How to make Spring Boot venture utilizing Spring Initializer?

The Spring Initializer is a web application that can produce a Spring Boot project structure for you. It doesn’t
create any application code. However, it will give you an essential project structure and either a Maven or a
Gradle build specification to fabricate your code with. You should simply compose the application code.

Spring Initializer can be utilized a few different ways, including

 An online interface.
 Via Spring Tool Suite.
 Using the Spring Boot CL

Q.How to enable HTTP/2 support in Spring Boot?


You can enable HTTP/2 support in Spring Boot as follows: server.http2.enabled=true

Example:-

@Bean public ConfigurableServletWebServerFactory tomcatCustomizer() {

TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();


factory.addConnectorCustomizers(connector -> connector.addUpgradeProtocol(new Http2Protocol()));

return factory;

You can enable HTTP/2 support in Spring Boot as follows: server.http2.enabled=true

Example:-
@Bean public ConfigurableServletWebServerFactory tomcatCustomizer() {

TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();


factory.addConnectorCustomizers(connector -> connector.addUpgradeProtocol(new Http2Protocol()));

return factory;

Q.How do you Enable HTTP response compression in spring boot?


To enable HTTP response compression in spring boot using GZIP you have to add below settings in your
application.properties file.

# Enabling HTTP response compression in spring boot


server.compression.enabled=true
server.compression.min-response-size=2048
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain

 Q.What is the difference between RequestMapping and GetMapping


in Spring Boot?
Both @GetMapping and @RequestMapping are annotations for mapping HTTP GET requests onto specific
handler methods in Spring boot. @GetMapping is a composed annotation that acts as a shortcut for
@RequestMapping. @GetMapping is the newer annotation.

Q.How do you configure error logging/debugging in Spring boot


application?
You can configure error logging/debugging in Spring boot application by applying the following settings in
application.properties or application.yml file.

logging.level.org.springframework.web: DEBUG

logging.level.org.hibernate: ERROR

Q.What is the use of @SpringBootApplication annotation?


@SpringBootApplication annotation was introduced in Spring Boot version 1.2.0. It is a convenience
annotation which is used in spring boot application to enable additions of beans using the classpath definitions.

Q.What is Auto Configuration in Spring boot?


Autoconfiguration is way in Spring Boot to configure a spring application automatically on the basis of
dependencies that are present on the classpath. It makes development easier and faster.

You can create a custom configuration for a MySQL data source in spring boot as

@Configuration
public class MySQLAutoconfiguration {

//...

Q.What does Spring Boot Starter Pom mean? Why Is It Useful?


Starters are an arrangement of advantageous reliance descriptors that you can incorporate into your application.
The starters contain a considerable amount of the dependencies that you have to get a task up and running
rapidly and with a steady, supported a set of managed transitive conditions.

The starter POMs are helpful reliance descriptors that can be added to your application’s Maven. In another
word, if you are building up a project that utilizes Spring Batch for batch preparing, you need to incorporate
spring-boot-starter-bunch that will import all the required conditions for the Spring Batch application. This
decreases the burden of looking at and designing all of the conditions required for a structure.

You might also like