Spring Framework Interview Questions Flashcards

1
Q

What is Spring Framework?

A

https://training.javatpoint.com/important-features-of-spring-framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Features of Spring Framework

A

https://training.javatpoint.com/important-features-of-spring-framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Spring Configuration File?

A

https://www.careerride.com/Spring-configuration-file.aspx#google_vignette

Question 3 from

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Spring – Understanding Inversion of Control with Example

A

https://www.geeksforgeeks.org/spring-understanding-inversion-of-control-with-example/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What do you understand by Dependency Injection?

A

https://www.geeksforgeeks.org/spring-dependency-injection-with-example/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the difference between constructor and setter injection?

A

https://www.geeksforgeeks.org/spring-dependency-injection-with-example/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Spring Beans?

A

https://stackoverflow.com/questions/17193365/what-in-the-world-are-spring-beans/17193458#17193458

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How is the configuration meta data provided to the spring container?

A

https://www.freetimelearning.com/software-interview-questions-and-answers.php?How-is-the-configuration-meta-data-provided-to-the-spring-container?&id=2164

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How is the configuration meta data provided to the spring container?

A

https://www.freetimelearning.com/software-interview-questions-and-answers.php?How-is-the-configuration-meta-data-provided-to-the-spring-container?&id=2164

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the bean scopes available in Spring?

A

https://www.tutorialspoint.com/spring/spring_bean_scopes.htm

Question 25 from

https://www.turing.com/interview-questions/spring-boot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain Bean life cycle in Spring Bean Factory Container.

A

https://www.edureka.co/community/17617/bean-life-cycle-in-spring-bean-factory-container

Question 10 from

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do you understand by Bean Wiring.

A

https://www.quora.com/What-is-bean-wiring-in-Spring-in-Java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is autowiring and name the different modes of it?

A

https://www.geeksforgeeks.org/spring-autowiring/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the limitations of autowiring?

A

Question 13

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Springboot

A

https://www.tutorialspoint.com/spring_boot/spring_boot_introduction.htm

Springboot interview question no 1

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Explain the advantages of using Spring Boot for application development.

A

Spring Boot helps to create stand-alone applications which can be started using java.jar (Doesn’t require configuring WAR files).
Spring Boot also offers pinpointed ‘started’ POMs to Maven configuration.
Has provision to embed Undertow, Tomcat, Jetty, or other web servers directly.
Auto-Configuration: Provides a way to automatically configure an application based on the dependencies present on the classpath.
Spring Boot was developed with the intention of lessening the lines of code.
It offers production-ready support like monitoring and apps developed using spring boot are easier to launch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Differentiate between Spring and Spring Boot.

A

https://www.geeksforgeeks.org/difference-between-spring-and-spring-boot/

Intermediate Question 1 from

https://www.turing.com/interview-questions/spring-boot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the features of Spring Boot?

A

https://docs.spring.io/spring-boot/docs/2.4.x/reference/html/spring-boot-features.html

https://www.interviewbit.com/spring-boot-interview-questions/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does @SpringBootApplication annotation do internally?

A

https://www.linkedin.com/pulse/understanding-springbootapplication-annotation-spring-punyakeerthi-bl-z1u5c?utm_source=share&utm_medium=member_ios&utm_campaign=share_via

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the effects of running Spring Boot Application as “Java Application”?

A

The application automatically launches the tomcat server as soon as it sees that we are running a web application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is Spring Boot dependency management system?

A

https://www.geeksforgeeks.org/spring-boot-dependency-management/#:~:text=Dependency%20is%20nothing%20but%20a,dependencies%20supremely%20easy%20for%20us.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are the possible sources of external configuration?

A

Spring Boot allows the developers to run the same application in different environments by making use of its feature of external configuration. This uses environment variables, properties files, command-line arguments, YAML files, and system properties to mention the required configuration properties for its corresponding environments. Following are the sources of external configuration:
Command-line properties – Spring Boot provides support for command-line arguments and converts these arguments to properties and then adds them to the set of environment properties.
Application Properties – By default, Spring Boot searches for the application properties file or its YAML file in the current directory of the application, classpath root, or config directory to load the properties.
Profile-specific properties – Properties are loaded from the application-{profile}.properties file or its YAML file. This file resides in the same location as that of the non-specific property files and the {profile} placeholder refers to an active profile or an environment.

Question 9 from

https://www.turing.com/interview-questions/spring-boot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Can we change the default port of the embedded Tomcat server in Spring boot?

A

Yes, we can change it by using the application properties file by adding a property of server.port and assigning it to any port you wish to.
For example, if you want the port to be 8081, then you have to mention server.port=8081. Once the port number is mentioned, the application properties file will be automatically loaded by Spring Boot and the specified configurations will be applied to the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Can you tell how to exclude any package without using the basePackages filter?

A

We can use the exclude attribute while using the annotation @SpringBootApplication as follows:
@SpringBootApplication(exclude= {Student.class})
public class InterviewBitAppConfiguration {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Can the default web server in the Spring Boot application be disabled?

A

Yes! application.properties is used to configure the web application type, by mentioning spring.main.web-application-type=none.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What are the uses of @RequestMapping and @RestController annotations in Spring Boot?

A

Springboot interview question no 13

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is Spring AOP and it’s terminology?

A

https://www.geeksforgeeks.org/aspect-oriented-programming-and-aop-in-spring-framework/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is an advice? Explain its types in spring.

A

https://www.tutorialspoint.com/springaop/springaop_advice_types.htm

https://docs.spring.io/spring-framework/reference/core/aop/ataspectj/advice.html

https://www.baeldung.com/spring-aop-advice-tutorial

Question 24 from

https://www.javatpoint.com/spring-interview-questions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is Spring AOP Proxy pattern?

A

https://www.dineshonjava.com/understanding-aop-proxies-chapter-31/

A proxy pattern is a well-used design pattern where a proxy is an object that looks like another object but adds special functionality to it behind the scenes.
Spring AOP follows proxy-based pattern and this is created by the AOP framework to implement the aspect contracts in runtime.
The standard JDK dynamic proxies are default AOP proxies that enables any interface(s) to be proxied. Spring AOP can also use CGLIB proxies that are required to proxy classes, rather than interfaces. In case a business object does not implement an interface, then CGLIB proxies are used by default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What are some of the classes for Spring JDBC API?

A

https://www.geeksforgeeks.org/spring-jdbc-template/

Spring JDBC question 4

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

How can you fetch records by Spring JdbcTemplate?

A

Spring JDBC question 5

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

Question 15 from

https://www.javatpoint.com/spring-interview-questions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is the Spring MVC framework?

A

https://www.geeksforgeeks.org/spring-mvc-framework/

SpringMVC framework question 1

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What are the benefits of Spring MVC framework over other MVC frameworks?

A

https://www.upgrad.com/blog/spring-mvc-flow-diagram/#:~:text=Fast%20development%3A%20The%20MVC%20spring,for%20application%20and%20framework%20classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is DispatcherServlet in Spring MVC? In other words, can you explain the Spring MVC architecture?

A

https://www.geeksforgeeks.org/spring-mvc-framework/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is a View Resolver pattern and explain its significance in Spring MVC?

A

https://www.geeksforgeeks.org/viewresolver-in-spring-mvc/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is the @Controller annotation used for?

A

https://www.geeksforgeeks.org/spring-controller-annotation-with-example/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What is the @Controller annotation used for?

A

https://www.geeksforgeeks.org/spring-controller-annotation-with-example/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

When to use @controller and @restcontroller

A

https://stackoverflow.com/questions/72211755/when-to-use-controller-and-when-restcontroller-annotation-in-restapi-based-on#:~:text=%40Controller%20is%20used%20to%20annotate,expect%20from%20that%20particular%20endpoint.

@Controller Map of the model object to view or template and make it human readable but @RestController simply returns the object and object data is directly written in HTTP response as JSON or

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Can you create a controller without using @Controller or @RestController annotations?

A

Yes! You can create a controller without @Controller or @RestController annotations by annotating the Spring MVC Controller classes using the @Component annotation. In this case, the real job of request mapping to handler method is done using the @RequestMapping annotation.

https://stackoverflow.com/questions/29410179/how-can-i-create-a-spring-controller-without-the-use-of-the-annotations

Yes, you can create a controller in Spring without using the @Controller or @RestController annotations. The @Controller and @RestController annotations are just convenience annotations that provide specific functionalities, but you can achieve the same functionality by using other annotations or configuration.

To create a controller without using @Controller or @RestController, you can use the following approach:

Implement the Controller Logic: Create a regular Java class that contains the logic for handling HTTP requests and generating responses.
Use Appropriate Annotations: Instead of @Controller or @RestController, you can use other annotations to specify the request mappings and the response type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What is ContextLoaderListener and what does it do?

A

https://stackoverflow.com/questions/11815339/role-purpose-of-contextloaderlistener-in-spring

The ContextLoaderListener loads and creates the ApplicationContext, so a developer need not write explicit code to do create it. In short, it is a listener that aids to bootstrap Spring MVC.
The application context is where Spring bean resides. For a web application, there is a subclass called WebAppliationContext.
The lifecycle of the ApplicationContext is tied to the lifecycle of the ServletContext by using ContextLoaderListener. The ServletContext from the WebApplicationContext can be obtained using the getServletContext() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

What are the differences between @RequestParam and @PathVariable annotations?

A

https://medium.com/javarevisited/difference-between-requestparam-and-pathvariable-in-spring-mvc-873bd6330bce#:~:text=%40RequestParam%20captures%20values%20from%20the,slashes%20(%E2%80%9C%2F%E2%80%9D).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What is the Model in Spring MVC?

A

Model is a reference to have the data for rendering.
It is always created and passed to the view in Spring MVC. If a mapped controller method has Model as a parameter, then that model instance is automatically injected to that method.
Any attributes set on the injected model would be preserved and passed to the View.

In the context of Spring MVC, the term “Model” represents the data layer. It is a map (similar to a java.util.Map) that contains data to be rendered by the View. This data is typically the outcome of executing your business logic, which you want to show to the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

What is the use of @Autowired annotation?

A

https://www.digitalocean.com/community/tutorials/spring-autowired-annotation#:~:text=Spring%20%40Autowired%20annotation%20is%20used,through%20spring%20bean%20configuration%20file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What is the role of @ModelAttribute annotation?

A

The annotation plays a very important role in binding method parameters to the respective attribute that corresponds to a model. Then it reflects the same on the presentation page. The role of the annotation also depends on what the developer is using that for. In case, it is used at the method level, then that method is responsible for adding attributes to it. When used at a parameter level, it represents that the parameter value is meant to be retrieved from the model layer.

https://www.geeksforgeeks.org/spring-mvc-modelattribute-annotation-with-example/

The @ModelAttribute annotation in Spring MVC is used to bind method parameters or method return values to model attributes. It plays a crucial role in the Model-View-Controller (MVC) architecture, where it helps transfer data between the Controller and the View.

The key role of @ModelAttribute is to facilitate data transfer between the Controller and the View. It allows you to pre-populate form data when displaying forms to users and automatically bind user inputs to model attributes when processing form submissions. Additionally, it helps in adding common attributes (like reference data) to the model across multiple controller methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What is the importance of the web.xml in Spring MVC?

A

https://stackoverflow.com/questions/5837122/can-someone-explain-the-spring-web-xml-file

web.xml is also known as the Deployment Descriptor which has definitions of the servlets and their mappings, filters, and lifecycle listeners. It is also used for configuring the ContextLoaderListener. Whenever the application is deployed, a ContextLoaderListener instance is created by Servlet container which leads to a load of WebApplicationContext.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What are the types of Spring MVC Dependency Injection?

A

https://www.codingninjas.com/studio/library/spring-dependency-injection#:~:text=The%20different%20types%20of%20dependency%20injections%20in%20Spring%20are%20constructor,according%20to%20the%20different%20requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What is the importance of session scope?

A

https://stackoverflow.com/questions/29413290/how-exactly-works-the-spring-session-scope-of-a-bean-what-is-the-default-scope

SpringMVC Interview question 14

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

What is the importance of @Required annotation?

A

https://www.linkedin.com/pulse/spring-boot-important-annotations-abid-anjum?utm_source=share&utm_medium=member_ios&utm_campaign=share_via

https://stackoverflow.com/questions/16769360/how-does-required-annotation-work-with-javaconfig

The annotation is used for indicating that the property of the bean should be populated via autowiring or any explicit value during the bean definition at the configuration time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Differentiate between the @Autowired and the @Inject annotations.

A

Spring MVC Interview question 16

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Are singleton beans thread-safe?

A

No, the singleton beans are not thread-safe because the concept of thread-safety essentially deals with the execution of the program and the singleton is simply a design pattern meant for the creation of objects. Thread safety nature of a bean depends on the nature of its implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

How can you achieve thread-safety in beans?

A

The thread safety can be achieved by changing the scope of the bean to request, session or prototype but at the cost of performance. This is purely based on the project requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

What is the significance of @Repository annotation?

A

@Repository annotation indicates that a component is used as the repository that acts as a means to store, search or retrieve data. These can be added to the DAO classes.

https://medium.com/@AlexanderObregon/understanding-the-role-of-the-repository-annotation-in-spring-data-access-95ec917c77b0#:~:text=The%20%40Repository%20annotation%20simplifies%20exception,thrown%20by%20the%20DAO%20layer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

How is the dispatcher servlet instantiated?

A

https://www.geeksforgeeks.org/what-is-dispatcher-servlet-in-spring/

The dispatcher servlet is instantiated by means of servlet containers such as Tomcat. The Dispatcher Servlet should be defined in web.xml The DispatcherServlet is instantiated by Servlet containers like Tomcat.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

How is the root application context in Spring MVC loaded?

A

The root application context is loaded using the ContextLoaderListener that belongs to the entire application. Spring MVC allows instantiating multiple DispatcherServlet and each of them have multiple contexts specific to them. They can have the same root context too.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

How does the Spring MVC flow look like? In other words, How does a DispatcherServlet know what Controller needs to be called when there is an incoming request to the Spring MVC?

A

A Dispatcher Servlet knows which controller to call by means of handler mappings. These mappings have the mapping between the controller and the requests. BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping are the two most commonly used handler mappings.

BeanNameUrlHandlerMapping: When the URL request matches the bean name, the class corresponding to the bean definition is the actual controller that is responsible for processing the request.
SimpleUrlHandlerMapping: Here, the mapping is very explicit. The number of URLs can be specified here and each URL is associated explicitly with a controller.
If the Spring MVC is configured using annotations, then @RequestMapping annotations are used for this purpose. The @RequestMapping annotation is configured by making use of the URI path, HTTP methods, query parameters, and the HTTP Headers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Where does the access to the model from the view come from?

A

The view requires access to the model to render the output as the model contains the required data meant for rendering. The model is associated with the controller that processes the client requests and finally encapsulates the response into the Model object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Why do we need BindingResults?

A

https://stackoverflow.com/questions/10413886/what-is-the-use-of-bindingresult-interface-in-spring-mvc#:~:text=%5B%20BindingResult%20%5D%20is%20Spring’s%20object%20that,object%20and%20throw%20an%20exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

What are Spring Interceptors?

A

https://www.geeksforgeeks.org/spring-boot-interceptor/#:~:text=Spring%20Boot%20Interceptor%20is%20an,an%20incoming%20or%20outgoing%20request%E2%80%9D.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Is there any need to keepspring-mvc.jar on the classpath or is it already present as part of spring-core?

A

The spring-mv.jar does not belong to the spring-core. This means that the jar has to be included in the project’s classpath if we have to use the Spring MVC framework in our project. For Java applications, the spring-mvc.jar is placed inside /WEB-INF/lib folder.

The spring-mvc.jar file is not part of the spring-core library, and they serve different purposes.

spring-core: This is the core Spring framework, which provides fundamental parts of the framework such as dependency injection and inversion of control.
spring-webmvc: This is the Spring MVC framework (typically named as spring-webmvc.jar not spring-mvc.jar), which is built on top of the core Spring framework and provides Model-View-Controller (MVC) architecture for building web applications.
So, if you’re building an application using the Spring MVC framework, you would need both spring-core and spring-webmvc on your classpath. These libraries are usually managed by a build tool like Maven or Gradle, and are automatically included when you specify them as dependencies in your build file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

What are the differences between the <context:annotation-config> vs <context:component-scan> tags?</context:component-scan></context:annotation-config>

A

<context:annotation-config> is used for activating applied annotations in pre-registered beans in the application context. It also registers the beans defined in the config file and it scans the annotations within the beans and activates them.

The <context:component-scan> tag does the task of <context:annotation-config> along with scanning the packages and registering the beans in the application context.

<context:annotation-config> = Scan and activate annotations in pre-registered beans.
<context:component-scan> = Register Bean + Scan and activate annotations in package.


context:annotation-config>: This is used to activate various annotations within Spring-managed beans. For example, if you have beans that are manually defined in your XML file and these beans have annotations like @Autowired, @PostConstruct, @PreDestroy, @Resource, etc., you need <context:annotation-config> to activate these annotations. However, it does not automatically detect and instantiate beans from the classpath.



<context:component-scan>: This tag does everything that <context:annotation-config> does, but it goes one step further. It scans the classpath for classes annotated with @Component, @Service, @Repository, @Controller, etc., and automatically registers them as beans in the Spring application context. In other words, it automatically detects and instantiates your beans. So, when you use <context:component-scan>, you don’t need to explicitly define each bean in your XML configuration file, as long as they are annotated correctly and exist within the base-package specified by <context:component-scan>.
</context:component-scan></context:component-scan></context:annotation-config></context:component-scan></context:annotation-config></context:component-scan></context:annotation-config></context:annotation-config></context:component-scan></context:annotation-config>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

How is the form data validation done in Spring Web MVC Framework?

A

Spring MVC interview question 28

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

Question 40 from

https://www.edureka.co/blog/interview-questions/spring-interview-questions/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

How to get ServletConfig and ServletContext objects in spring bean?

A

This can be done by either implementing the spring-aware interfaces or by using the @Autowired annotation.

@Autowired
private ServletContext servletContext;
@Autowired
private ServletConfig servletConfig;

Question 19 from

https://www.baeldung.com/spring-interview-questions#Q17

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

Differentiate between a Bean Factory and an Application Context.

A

https://www.geeksforgeeks.org/spring-difference-between-beanfactory-and-applicationcontext/

Question 42 from

https://www.edureka.co/blog/interview-questions/spring-interview-questions/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

How are i18n and localization supported in Spring MVC?

A

Spring MVC framework question 31

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

Internationalization (i18n) and localization (L10n) are important features for applications that need to support multiple languages or locales. In Spring MVC, these are supported using a combination of LocaleResolver, LocaleChangeInterceptor, and message source properties files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

What do you understand by MultipartResolver?

A

Spring MVC interview question 32

https://www.interviewbit.com/spring-interview-questions/?sign_up_medium=ib_article_auth_blocker/#

MultipartResolver is an interface defined in Spring MVC framework that is used for uploading files. When a form in a Spring web application is submitted and it has enctype=”multipart/form-data”, the MultipartResolver implementation handles the file upload part of the request.

The MultipartResolver is part of the Spring DispatcherServlet’s configuration, so you’ll define it in your Spring configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

How is it possible to use the Tomcat JNDI DataSource in the Spring applications?

A

To use the servlet container which is configured in the JNDI (Java Naming and Directory Interface) DataSource, the DataSource bean has to be configured in the spring bean config file and then injected into the beans as dependencies. Post this, the DataSource bean can be used for performing database operations by means of the JdbcTemplate. The syntax for registering a MySQL DataSource bean:

<bean>
<property></property>
</bean>

To use a Tomcat JNDI DataSource in a Spring application:

Setup DataSource in Tomcat: Configure the DataSource in Tomcat’s context.xml file with the necessary parameters (username, password, driverClassName, etc).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

What will be the selection state of a checkbox input if the user first checks the checkbox and gets validation errors in other fields and then unchecks the checkbox after getting the errors?

A

The validation is generally performed during HTTP POST requests. During HTTP requests, if the state of the checkbox is unchecked, then HTTP includes the request parameter for the checkbox thereby not picking up the updated selection. This can be fixed by making use of a hidden form field that starts with _ in the Spring MVC.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

Advantages of Spring Framework With Limitations

A

https://data-flair.training/blogs/advantages-of-spring/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
Q

What are the modules of spring framework?

A

https://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/html/overview.html

https://www.edureka.co/blog/interview-questions/spring-interview-questions/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
70
Q

Roles and types of IOC containers in spring

A

https://www.geeksforgeeks.org/spring-understanding-inversion-of-control-with-example/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
71
Q

In which scenario, you will use singleton and prototype scope?

A

Singleton scope should be used with EJB stateless session bean and prototype scope with EJB stateful session bean.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
72
Q

What is a stateless session bean

A

https://www.javatpoint.com/stateless-session-bean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
73
Q

Difference between stateless and state full

A

https://www.interviewbit.com/blog/stateful-vs-stateless/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

What are the transaction management supports provided by spring?

A

https://www.tutorialspoint.com/spring/spring_transaction_management.htm#:~:text=Spring%20supports%20both%20programmatic%20and,need%20of%20an%20application%20server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
75
Q

What are the advantages of JdbcTemplate in spring?

A

https://www.javatpoint.com/spring-JdbcTemplate-tutorial#:~:text=Advantage%20of%20Spring%20JdbcTemplate&text=Spring%20JdbcTemplate%20eliminates%20all%20the,lot%20of%20work%20and%20time.

Question 13 from

https://www.javatpoint.com/spring-interview-questions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
76
Q

What is the advantage of NamedParameterJdbcTemplate?

A

https://prateek-ashtikar512.medium.com/spring-jdbc-namedparameterjdbctemplate-2e7cd08c49e6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
77
Q

What is the advantage of SimpleJdbcTemplate?

A

https://docs.spring.io/spring-framework/docs/2.5.x/reference/jdbc.html#:~:text=SimpleJdbcTemplate%20%2D%20this%20class%20combines%20the,an%20easier%20to%20use%20API.

Question 17 from

https://www.javatpoint.com/spring-interview-questions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
78
Q

What are the advantages of spring AOP?

A

https://medium.com/@AlexanderObregon/cross-cutting-concerns-in-spring-microservices-with-aspect-oriented-programming-aop-de72c52e7639

https://www.jbktutorials.com/spring-aop/advantages-of-spring-aop.php#gsc.tab=0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
79
Q

What is JoinPoint?

A

https://docs.spring.io/spring-framework/docs/2.0.x/reference/aop.html#:~:text=Join%20point%3A%20A%20point%20during,always%20represents%20a%20method%20execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
80
Q

Does spring framework support all JoinPoints?

A

No, spring framework supports method execution joinpoint only.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
81
Q

What is Pointcut?

A

https://www.tutorialspoint.com/springaop/springaop_pointcut_methods1.htm

https://docs.spring.io/spring-framework/reference/core/aop/ataspectj/pointcuts.html

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
82
Q

What is Aspect?

A

https://www.digitalocean.com/community/tutorials/spring-aop-example-tutorial-aspect-advice-pointcut-joinpoint-annotations#:~:text=Aspect%3A%20An%20aspect%20is%20a,as%20Aspect%20using%20%40Aspect%20annotation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
Q

What is Introduction?

A

Introduction represents introduction of new fields and methods for a type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
84
Q

What is target object?

A

https://stackoverflow.com/questions/56692011/what-is-a-target-object-in-spring-aop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
85
Q

What is weaving?

A

https://www.simplilearn.com/tutorials/spring-tutorial/spring-aop-aspect-oriented-programming#:~:text=Weaving%3A,normally%20performs%20weaving%20at%20runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
86
Q

Does spring perform weaving at compile time?

A

No, spring framework performs weaving at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
Q

What are the AOP implementation?

A

There are 3 AOP implementation.

Spring AOP
Apache AspectJ
JBoss AOP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
88
Q

What is the front controller class of Spring MVC?

A

https://www.javatpoint.com/spring-mvc-tutorial#:~:text=Front%20Controller%20%2D%20In%20Spring%20Web,of%20the%20Spring%20MVC%20application.

https://www.geeksforgeeks.org/spring-mvc-framework/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
89
Q

Does spring MVC provide validation support?

A

https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-validation.html#:~:text=Spring%20MVC%20has%20built%2Din,support%20works%20on%20two%20levels.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
Q

Which Is the Best Way of Injecting Beans and Why?

A

The recommended approach is to use constructor arguments for mandatory dependencies and setters for optional ones. This is because constructor injection allows injecting values to immutable fields and makes testing easier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
91
Q

What Is the Default Bean Scope in Spring Framework?

A

By default, a Spring Bean is initialized as a singleton.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

What Does the Spring Bean Life Cycle Look Like?

A

Question 12 from

https://www.baeldung.com/spring-interview-questions#Q6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
93
Q

What Is the Spring Java-Based Configuration?

A

It’s one of the ways of configuring Spring-based applications in a type-safe manner. It’s an alternative to the XML-based configuration.

https://www.tutorialspoint.com/spring/spring_java_based_configuration.htm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
94
Q

Can We Have Multiple Spring Configuration Files in One Project?

A

Question 14 from

https://www.baeldung.com/spring-interview-questions#Q6

95
Q

What Is Spring Security?

A

https://spring.io/projects/spring-security/

96
Q

Name Some of the Design Patterns Used in the Spring Framework?

A

https://medium.com/@bubu.tripathy/design-patterns-used-in-spring-framework-60df94fd3400

97
Q

How Does the Scope Prototype Work?

A

https://stackoverflow.com/questions/21969044/when-to-use-spring-prototype-scope

Question 18 from

https://www.baeldung.com/spring-interview-questions#Q17

98
Q

How Does the @RequestMapping Annotation Work?

A

The @RequestMapping annotation is used to map web requests to Spring Controller methods. In addition to simple use cases, we can use it for mapping of HTTP headers, binding parts of the URI with @PathVariable, and working with URI parameters and the @RequestParam annotation.

99
Q

What Is Spring JdbcTemplate Class and How to Use It?

A

Question 22 from

https://www.baeldung.com/spring-interview-questions#Q17

100
Q

How to Enable Transactions in Spring and What Are Their Benefits?

A

There are two distinct ways to configure Transactions — with annotations or by using Aspect-Oriented Programming (AOP) — each with their advantages.

Here are the benefits of using Spring Transactions, according to the official docs:

Provide a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA and JDO
Support declarative transaction management
Provide a simpler API for programmatic transaction management than some complex transaction APIs such as JTA
Integrate very well with Spring’s various data access abstractions

101
Q

What Is Spring DAO?

A

https://docs.spring.io/spring-framework/reference/data-access/dao.html#:~:text=The%20Data%20Access%20Object%20(DAO,JPA)%20in%20a%20consistent%20way.

Question 24 from

https://www.baeldung.com/spring-interview-questions#Q17

102
Q

What Is Reactive Programming?

A

Question 28 from

https://www.baeldung.com/spring-interview-questions#Q24

103
Q

What Is Spring WebFlux?

A

https://www.digitalocean.com/community/tutorials/spring-webflux-reactive-programming

104
Q

What Are the Mono and Flux Types?

A

https://medium.com/javarevisited/difference-between-mono-and-flux-in-spring-webflux-6f260059d199#:~:text=A%20Mono%20is%20a%20reactive,of%20zero%20to%20many%20elements.

105
Q

What Is the Use of WebClient and WebTestClient?

A

https://docs.spring.io/spring-framework/reference/testing/webtestclient.html#:~:text=It%20wraps%20Spring’s%20WebClient%20and,server%20request%20and%20response%20objects.

https://docs.spring.io/spring-framework/reference/web/webflux-webclient.html

106
Q

What Are the Disadvantages of Using Reactive Streams?

A

There are some major disadvantages to using reactive streams:

Troubleshooting a Reactive application is a bit difficult, so be sure to check out our tutorial on debugging reactive streams for some handy debugging tips.
There is limited support for reactive data stores since traditional relational data stores have yet to embrace the reactive paradigm.
There’s an extra learning curve when implementing.

107
Q

Is Spring 5 Compatible With Older Versions of Java?

A

In order to take advantage of Java 8 features, the Spring codebase has been revamped. This means older versions of Java cannot be used. So, the framework requires a minimum of Java 8.

108
Q

Can We Use Both Web MVC and WebFlux in the Same Application?

A

As of now, Spring Boot will only allow either Spring MVC or Spring WebFlux, as Spring Boot tries to auto-configure the context depending on the dependencies that exist in its classpath.

Also, Spring MVC cannot run on Netty. Moreover, MVC is a blocking paradigm and WebFlux is a non-blocking style. So, we shouldn’t be mixing both together because they serve different purposes.

109
Q

Why Springboot if we have spring

A

https://www.turing.com/kb/spring-vs-spring-boots-best-web-apps#:~:text=While%20Spring%20is%20the%20best,the%20simplest%20and%20easiest%20method.

Question No 3 from

https://www.interviewbit.com/spring-boot-interview-questions/

110
Q

How to secure micro services in spring?

A

https://www.geeksforgeeks.org/best-practices-to-secure-microservices-with-spring-security/

https://www.linkedin.com/pulse/spring-microservices-security-best-practices-abid-anjum?utm_source=share&utm_medium=member_ios&utm_campaign=share_via

111
Q

Key Components of Spring Boot Framework

A

https://www.digitalocean.com/community/tutorials/key-components-and-internals-of-spring-boot-framework

Question No 7 from

https://www.edureka.co/blog/interview-questions/spring-interview-questions/

112
Q

What are the various ways of using Spring Framework?

A

Question No 8 from

https://www.edureka.co/blog/interview-questions/spring-interview-questions/

113
Q

List some of the benefits of IoC.

A

Question No 15 from

https://www.edureka.co/blog/interview-questions/spring-interview-questions/

114
Q

In which scenario, you will use singleton and prototype scope?

A

Use Singleton Scope when you want to have only one instance shared across the entire application.

Use Prototype Scope when you want a new instance created every time it’s requested, providing independence for each part of the application.

115
Q

How does the Spring MVC flow look like? In other words, How does a DispatcherServlet know what Controller needs to be called when there is an incoming request to the Spring MVC?

A

The Spring MVC flow involves several components working together to handle incoming requests and route them to the appropriate controllers for processing.

The DispatcherServlet plays a central role in the Spring MVC flow. It receives incoming requests, selects the appropriate controller based on the URL mapping, invokes the controller method to handle the request, prepares the model data and view, resolves the view, and finally sends the response back to the client. The flow is orchestrated through a combination of handler mappings, controllers, view resolvers, and views, allowing Spring MVC to handle various types of requests and produce dynamic responses.

116
Q

How to get ServletConfig and ServletContext objects in spring bean?

A

In a Spring application, you can access ServletConfig and ServletContext objects by implementing the ServletContextAware and ServletConfigAware interfaces. These interfaces provide setter methods that Spring will use to inject the necessary objects.

117
Q

What is the starter dependency of the Spring boot module?

A

Spring boot provides numbers of starter dependency, here are the most commonly used -

Data JPA starter.
Test Starter.
Security starter.
Web starter.
Mail starter.
Thymeleaf starter.

Spring boot starter is a maven template that contains a collection of all the relevant transitive dependencies that are needed to start a particular functionality.
Like we need to import spring-boot-starter-web dependency for creating a web application.

<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-starter-web </artifactId>
</dependency>

118
Q

Spring Boot – Starters

A

https://www.geeksforgeeks.org/spring-boot-starters/#:~:text=Spring%20Boot%20Starters%20are%20dependency,dependencies%20under%20a%20single%20name.

119
Q

How does Spring Boot works?

A

Spring Boot automatically configures your application based on the dependencies you have added to the project by using annotation. The entry point of the spring boot application is the class that contains @SpringBootApplication annotation and the main method.

Spring Boot automatically scans all the components included in the project by using @ComponentScan annotation.

120
Q

What is the purpose of using @ComponentScan in the class files?

A

Spring Boot application scans all the beans and package declarations when the application initializes. You need to add the @ComponentScan annotation for your class file to scan your components added to your project.

121
Q

How does a spring boot application get started?

A

Just like any other Java program, a Spring Boot application must have a main method. This method serves as an entry point, which invokes the SpringApplication#run method to bootstrap the application.

122
Q

What is Spring Initializer?

A

Spring Initializer is a web application that helps you to create an initial spring boot project structure and provides a maven or gradle file to build your code. It solves the problem of setting up a framework when you are starting a project from scratch.

123
Q

What is Spring Boot CLI and what are its benefits?

A

Spring Boot CLI is a command-line interface that allows you to create a spring-based java application using Groovy.

Example: You don’t need to create getter and setter method or access modifier, return statement. If you use the JDBC template, it automatically loads for you.

124
Q

What are the most common Spring Boot CLI commands?

A

Question 12 from

https://www.interviewbit.com/spring-boot-interview-questions/

125
Q

What Are the Basic Annotations that Spring Boot Offers?

A

The primary annotations that Spring Boot offers reside in its org.springframework.boot.autoconfigure and its sub-packages. Here are a couple of basic ones:

@EnableAutoConfiguration – to make Spring Boot look for auto-configuration beans on its classpath and automatically apply them.

@SpringBootApplication – used to denote the main class of a Boot Application. This annotation combines @Configuration, @EnableAutoConfiguration, and @ComponentScan annotations with their default attributes.

Question 12 from

https://www.simplilearn.com/spring-boot-interview-questions-article

126
Q

Can we create a non-web application in Spring Boot

A

Yes, we can create a non-web application by removing the web dependencies from the classpath along with changing the way Spring Boot creates the application context

127
Q

Is it possible to change the port of the embedded Tomcat server in Spring Boot?

A

Yes, it is possible. By using the server.port in the application.properties.

128
Q

What is the default port of tomcat in spring boot?

A

The default port of the tomcat server-id 8080. It can be changed by adding sever.port properties in the application.property file.

129
Q

Can we override or replace the Embedded tomcat server in Spring Boot?

A

Yes, we can replace the Embedded Tomcat server with any server by using the Starter dependency in the pom.xml file. Like you can use spring-boot-starter-jetty as a dependency for using a jetty server in your project.

130
Q

Can we disable the default web server in the Spring boot application?

A

Yes, we can use application.properties to configure the web application type i.e spring.main.web-application-type=none.

131
Q

How to disable a specific auto-configuration class?

A

You can use exclude attribute of @EnableAutoConfiguration if you want auto-configuration not to apply to any specific class.

//use of exclude
@EnableAutoConfiguration(exclude={className})

https://www.baeldung.com/spring-data-disable-auto-config

132
Q

Describe the flow of HTTPS requests through the Spring Boot application?

A

Advanced Question 11 from

https://www.interviewbit.com/spring-boot-interview-questions/

133
Q

What is the difference between RequestMapping and GetMapping?

A

RequestMapping can be used with GET, POST, PUT, and many other request methods using the method attribute on the annotation. Whereas getMapping is only an extension of RequestMapping which helps you to improve on clarity on request.

134
Q

What is the use of Profiles in spring boot?

A

While developing the application we deal with multiple environments such as dev, QA, Prod, and each environment requires a different configuration. For eg., we might be using an embedded H2 database for dev but for prod, we might have proprietary Oracle or DB2. Even if DBMS is the same across the environment, the URLs will be different.

To make this easy and clean, Spring has the provision of Profiles to keep the separate configuration of environments.

Question 26 from

https://www.simplilearn.com/spring-boot-interview-questions-article

135
Q

What is Spring Actuator? What are its advantages?

A

https://www.geeksforgeeks.org/spring-boot-actuator/

136
Q

How to enable Actuator in Spring boot application?

A

To enable the spring actuator feature, we need to add the dependency of “spring-boot-starter-actuator” in pom.xml.

<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-starter-actuator </artifactId>
</dependency>

137
Q

What are the actuator-provided endpoints used for monitoring the Spring boot application?

A

https://www.geeksforgeeks.org/spring-boot-actuator/

Advanced Question 16

https://www.interviewbit.com/spring-boot-interview-questions/

138
Q

How to get the list of all the beans in your Spring boot application?

A

Spring Boot actuator “/Beans” is used to get the list of all the spring beans in your application.

139
Q

How to check the environment properties in your Spring boot application?

A

Spring Boot actuator “/env” returns the list of all the environment properties of running the spring boot application.

140
Q

How to enable debugging log in the spring boot application?

A

Debugging logs can be enabled in three ways -

We can start the application with –debug switch.
We can set the logging.level.root=debug property in application.property file.
We can set the logging level of the root logger to debug in the supplied logging configuration file.

141
Q

Where do we define properties in the Spring Boot application?

A

You can define both application and Spring boot-related properties into a file called application.properties. You can create this file manually or use Spring Initializer to create this file. You don’t need to do any special configuration to instruct Spring Boot to load this file, If it exists in classpath then spring boot automatically loads it and configure itself and the application code accordingly.

142
Q

What makes Spring Boot superior to JAX-RS?

A

By leveraging Spring Boot features, users can experience significant advantages over JAX-RS, including:

Fast deployment
High scalability
Container compatibility
Minimal configuration
Lower production time
Increased productivity
Reduced development time
Easy monitoring and management of applications

143
Q

What Spring Boot features help develop Microservices Applications?

A

Primarily used for developing microservices-based applications, Spring Boot offers the following key features for configuring, developing, and deploying microservices architecture.

Integrates a tool called the Actuator, which enables users to manage and monitor applications
Provides support for embedded servers, such as Jetty and Tomcat
Users can simply run war files, without deploying it
Includes an Auto-Configuration functionality, allowing users to configure Spring applications automatically
Supports HTTP client Feign

144
Q

Why Spring Boot is preferred over any other framework?

A

Question 4 from

https://www.simplilearn.com/spring-boot-interview-questions-article

145
Q

What are the key dependencies of Spring Boot?

A

Mentioned below are important Spring Boot dependencies that need to be added to a Gradle-based or Maven-based application, to ensure application compatibility with Spring Boot features.

146
Q

How do you create a Spring Boot project using Spring Initializer?

A

Question 9 from

https://www.simplilearn.com/spring-boot-interview-questions-article

147
Q

How do you create a Spring Boot project using boot CLI?

A

Question 10 from

https://www.simplilearn.com/spring-boot-interview-questions-article

148
Q

What are the Spring Boot properties?

A

Spring Boot Properties files are used to configure its auto-configuration and application properties. Spring Boot has many properties that can be used to configure the behavior of the application. Some of the commonly used properties in Spring Boot include server.port, spring.profiles.active, spring.datasource.url, spring.jpa.show-sql, and many more.

149
Q

What is thyme leaf?

A

Thyme leaf is a popular templating engine used in Spring Boot applications for building dynamic web pages. Moreover, it is humanly readable and developers can use it to create templates that can be rendered in HTML

150
Q

How to use thyme leaf?

A

To use Thymeleaf in a Spring Boot application you should include the thymeleaf-spring-boot-starter dependency in your project.

151
Q

How do you connect Spring Boot to the database using JPA?

A

To connect Spring Boot to a database using JPA, configure the JPA properties in the application.properties or application.yml file.

152
Q

How to connect the Spring Boot application to a database using JDBC?

A

To connect the Spring Boot to a database using JDBC, configure the JDBC properties in the application.properties or application.yml file.

153
Q

How do you create a Spring Boot application using Spring Starter Project Wizard?

A

Follow the steps mentioned below to create a Spring Boot application using the Spring Starter Project Wizard, you need to follow these steps:

Open your preferred IDE and select the “New Project” option.
Next choose the “Spring Initializr” or “Spring Starter Project” option.
Fill in the required project information, such as project name, description, and dependencies.
Click on “Generate” to create the project structure and download the necessary dependencies.
Start coding your application logic.

154
Q

What annotations are used to create an Interceptor?

A

Question 24 from

https://www.simplilearn.com/spring-boot-interview-questions-article

155
Q

What is a Swagger in Spring Boot?

A

https://www.codingninjas.com/studio/library/swagger-in-spring-boot#:~:text=Swagger%20in%20Spring%20Boot%20is,helps%20implement%20the%20API%20specification.

Question 25 from

https://www.simplilearn.com/spring-boot-interview-questions-article

156
Q

What differentiates Spring Data JPA and Hibernate?

A

Question 27 from

https://www.simplilearn.com/spring-boot-interview-questions-article

157
Q

How can you enable the auto-configuration feature in Spring Boot?

A

Question 7 from

https://www.turing.com/interview-questions/spring-boot

158
Q

What is the purpose of the application.properties (or application.yml) file?

A

Question 10 from

https://www.turing.com/interview-questions/spring-boot

159
Q

Describe the Spring Boot auto-configuration mechanism.

A

https://www.turing.com/interview-questions/spring-boot

160
Q

Explain the difference between @Component, @Repository, @Service, and @Controller annotations in Spring Boot.

A

Question 13 from

https://www.turing.com/interview-questions/spring-boot

161
Q

How can you implement logging in a Spring Boot application?

A

Question 15 from

https://www.turing.com/interview-questions/spring-boot

162
Q

What is the purpose of the SpringApplication.run() method?

A

The SpringApplication.run() method is used to bootstrap and launch a Spring Boot application. It is typically invoked from the main method of the application’s entry point class.

The run() method initializes the Spring application context, performs auto-configuration, starts the embedded server, and starts the application lifecycle. It returns an instance of the ApplicationContext, allowing access to the application context and its beans.

163
Q

How does Spring Boot handle data validation?

A

Question 18 from

https://www.turing.com/interview-questions/spring-boot

164
Q

How does Spring Boot integrate with containerization platforms like Docker and Kubernetes?

A

Question 20 from

https://www.turing.com/interview-questions/spring-boot

165
Q

Explain the concept of message-driven microservices using Spring Boot and Apache Pulsar.

A

Question 21 from

https://www.turing.com/interview-questions/spring-boot

166
Q

What is the purpose of the @Value annotation in Spring Boot?

A

Question 22 from

https://www.turing.com/interview-questions/spring-boot

167
Q

Describe the role of the CommandLineRunner and ApplicationRunner interfaces in Spring Boot.

A

Question 23 from

https://www.turing.com/interview-questions/spring-boot

168
Q

How can you implement pagination in a Spring Boot application?

A

Question 24 from

https://www.turing.com/interview-questions/spring-boot

169
Q

What is the purpose of the @Qualifier annotation in Spring Boot?

A

Question 26 from

https://www.turing.com/interview-questions/spring-boot

170
Q

How does Spring Boot handle exception logging and error handling

A

Question 27 from

https://www.turing.com/interview-questions/spring-boot

171
Q

Describe the purpose and usage of the @RestControllerAdvice annotation

A

Question 28 from

https://www.turing.com/interview-questions/spring-boot

172
Q

What is the purpose of the @ConfigurationProperties annotation in Spring Boot?

A

Question 29 from

https://www.turing.com/interview-questions/spring-boot

173
Q

Describe the purpose and usage of the @DynamicPropertySource annotation in Spring Boot testing.

A

Question 30 from

https://www.turing.com/interview-questions/spring-boot

174
Q

What is the purpose of the @TransactionalEventListener annotation in Spring Boot?

A

Question 31 from

https://www.turing.com/interview-questions/spring-boot

175
Q

What is the purpose of the @Scheduled annotation in Spring Boot?

A

Question 32 from

https://www.turing.com/interview-questions/spring-boot

176
Q

Describe the role of the @Profile annotation in Spring Boot.

A

The @Profile annotation is used to activate or deactivate specific configuration components or beans based on the current environment or profile in a Spring Boot application. Annotating a class or method with @Profile and specifying the desired profile name lets you control when that component or bean should be active. This allows you to have different configurations for different deployment environments such as development, testing, or production.

177
Q

What is the purpose of Spring Boot’s dynamic reloading and how does it work?

A

Question 34 from

https://www.turing.com/interview-questions/spring-boot

178
Q

Explain the concept of externalized logging in Spring Boot using Logback or Log4j2.

A

Question 35 from

https://www.turing.com/interview-questions/spring-boot

179
Q

Explain the concept of reactive messaging with Spring Boot and Apache Kafka Streams.

A

Question 37 from

https://www.turing.com/interview-questions/spring-boot

180
Q

Describe the purpose and usage of the @Transactional(propagation = Propagation.NESTED) annotation.

A

Question 38 from

https://www.turing.com/interview-questions/spring-boot

181
Q

What is the purpose of the @DataJpaTest annotation in Spring Boot testing?

A

Question 39 from

https://www.turing.com/interview-questions/spring-boot

182
Q

Describe the purpose and usage of the Spring Boot Admin Server for monitoring and managing applications.

A

Question 40 from

https://www.turing.com/interview-questions/spring-boot

183
Q

How can you implement exception handling in a Spring Boot application?

A

Intermediate Question 3 from

https://www.turing.com/interview-questions/spring-boot

184
Q

How does Spring Boot support database operations?

A

Spring Boot provides excellent support for database operations through its integration with Spring Data JPA. By defining entities and repositories, you can perform CRUD (Create, Read, Update, Delete) operations on databases with minimal boilerplate code.

Spring Boot automatically configures the database connection and transaction management, and provides powerful querying capabilities.

185
Q

How can you implement caching in a Spring Boot application?

A

Caching in a Spring Boot application can be implemented using the @Cacheable, @CacheEvict, and other cache-related annotations provided by the Spring Framework. Adding these annotations to methods lets you cache the results and improve performance. Spring Boot integrates with popular caching providers like Ehcache, Hazelcast, and Redis.

186
Q

How can you enable cross-origin resource sharing (CORS) in a Spring Boot application?

A

To enable CORS in a Spring Boot application, you can use the @CrossOrigin annotation at the controller level or globally configure CORS using a WebMvcConfigurer bean. The annotation allows you to specify the allowed origins, HTTP methods, headers, and other CORS-related settings. Enabling CORS ensures that web browsers can make requests to your application from different domains.

187
Q

Explain the concept of the Spring Boot Actuator and its major features.

A

Intermediate Question 11 from

https://www.turing.com/interview-questions/spring-boot

188
Q

How can you integrate Spring Security in a Spring Boot application?

A

Intermediate Question 12 from

https://www.turing.com/interview-questions/spring-boot

189
Q

Explain the concept of Spring Data REST and its advantages.

A

Intermediate Question 16 from

https://www.turing.com/interview-questions/spring-boot

190
Q

Explain the concept of Spring Data REST and its advantages.

A

Intermediate Question 16 from

https://www.turing.com/interview-questions/spring-boot

191
Q

How can you implement file upload and download functionality in a Spring Boot application?

A

Intermediate Question 17 from

https://www.turing.com/interview-questions/spring-boot

192
Q

Describe the purpose and usage of the @Async annotation in Spring Boot

A

intermediate Question 18

https://www.turing.com/interview-questions/spring-boot

193
Q

What is the role of the embedded servlet container in Spring Boot?

A

Intermediate Question 19

https://www.turing.com/interview-questions/spring-boot

194
Q

How can you implement request and response logging in a Spring Boot application?

A

Intermediate Question 20

https://www.turing.com/interview-questions/spring-boot

195
Q

Explain the concept of reactive data access in Spring Boot using Spring Data R2DBC.

A

Intermediate Question 21

https://www.turing.com/interview-questions/spring-boot

196
Q

How can you perform asynchronous messaging using Spring Boot and RabbitMQ?

A

Intermediate Question 22

https://www.turing.com/interview-questions/spring-boot

197
Q

Describe the purpose and usage of the @Conditional annotation in Spring Boot.

A

The @Conditional annotation in Spring Boot allows you to conditionally activate or deactivate beans or configurations based on specific conditions. By annotating a bean or configuration class with @Conditional and providing a condition class implementing the Condition interface, you can control whether the bean or configuration should be created and registered based on runtime conditions. This enables flexible configuration based on environment, properties, or other factors.

198
Q

What is the purpose of the @SpringBootTest annotation in Spring Boot testing?

A

The @SpringBootTest annotation is used to bootstrap a Spring Boot application context for testing purposes. It allows you to load the entire application context, including all configurations and beans, during integration tests.

@SpringBootTest provides features like auto-configuration, dependency injection, and easy access to application-specific components, enabling comprehensive testing of Spring Boot applications.

199
Q

Explain the concept of Spring Boot’s actuator health checks and customizing health indicators.

A

Spring Boot’s actuator health checks are endpoints provided by the Actuator that give insights into the application’s health. By default, health indicators check the overall system health. You can customize them by implementing the HealthIndicator interface and registering them with the application context.

Custom health indicators allow you to monitor specific aspects of the application’s health such as database connectivity, external service availability, or custom health checks.

200
Q

How can you secure REST APIs in a Spring Boot application using JSON Web Tokens (JWT)?

A

You can secure REST APIs in a Spring Boot application using JSON Web Tokens (JWT) by integrating Spring Security and JWT libraries. Spring Security provides mechanisms for authentication and authorization, while JWT facilitates token-based authentication.

By configuring Spring Security filters, implementing authentication and authorization providers, and validating JWT tokens, you can protect your REST APIs and control access based on user roles and permissions.

201
Q

Describe the purpose and usage of the @EntityScan annotation in Spring Boot.

A

The @EntityScan annotation is used to specify the base packages to scan for entity classes in a Spring Boot application. When using JPA (Java Persistence API) with Spring Boot, @EntityScan helps the JPA provider locate and manage entity classes.

By default, Spring Boot scans the package of the application’s main class and its sub-packages. However, if entity classes are located in different packages, you need to use @EntityScan to include those packages.

202
Q

What is the purpose of the @Retryable annotation in Spring Boot?

A

The @Retryable annotation is used to specify that a method should be retried if it fails due to specified exceptions. Adding @Retryable and configuring the desired retry behavior enables Spring Boot to automatically retry the method when exceptions occur.

This can be useful for handling transient errors, such as network timeouts or temporary resource unavailability, and ensuring the successful execution of critical operations.

203
Q

Explain the concept of auto-reconfiguration in Spring Boot and its limitations.

A

Auto-reconfiguration in Spring Boot is a feature that automatically configures certain components and dependencies based on the classpath and available resources. It simplifies the configuration process by detecting and configuring components like data sources, messaging brokers, and caches.

Auto-reconfiguration has limitations when it comes to complex or custom configurations. It may not always provide the desired configuration out of the box. In such cases, manual configuration may be required.

204
Q

How can you implement distributed caching in a Spring Boot application using Hazelcast or Redis?

A

To implement distributed caching in a Spring Boot application with Hazelcast or Redis, you can leverage the respective cache providers’ integration libraries. Configuring the cache manager and cache-related settings lets you enable distributed caching.

Spring Boot simplifies the setup and configuration process by providing auto-configuration support for both Hazelcast and Redis. Additionally, you can annotate methods with cache-related annotations like @Cacheable or @CacheEvict to cache and retrieve data efficiently.

205
Q

How can you create a Spring Boot application using Gradle?

A

Advanced Question 1

https://www.turing.com/interview-questions/spring-boot

206
Q

How can you customize the default error pages in a Spring Boot application?

A

To customize the default error pages in a Spring Boot application, you can create an error page template or controller method that handles the error. Defining an error template with the appropriate name and placing it in the src/main/resources/templates/error directory enables Spring Boot to automatically render that template for the corresponding error status code.

Alternatively, you can create a controller method with @ExceptionHandler annotation to handle specific exceptions and return a custom error response.

207
Q

How can you create a Spring Boot application using Maven?

A

Advanced Question 3

https://www.turing.com/interview-questions/spring-boot

208
Q

What are the different deployment options for a Spring Boot application?

A

Advanced Question 5

https://www.turing.com/interview-questions/spring-boot

209
Q

Describe the process of creating a RESTful API using Spring Boot.

A

Advanced Question 6

https://www.turing.com/interview-questions/spring-boot

210
Q

How does Spring Boot integrate with messaging systems such as RabbitMQ?

A

Spring Boot provides integration with messaging systems like RabbitMQ through the Spring AMQP project. To integrate RabbitMQ with a Spring Boot application, you can include the spring-boot-starter-amqp dependency and configure the necessary properties in the application’s configuration file (application.properties or application.yml).

You can use the RabbitTemplate class to send messages to RabbitMQ and consume messages using @RabbitListener annotations on appropriate methods.

211
Q

Explain the concept of Spring Boot Data JPA and provide an example.

A

Advanced Question 8

https://www.turing.com/interview-questions/spring-boot

212
Q

How can you handle large file uploads in a Spring Boot application?

A

To handle large file uploads in a Spring Boot application, you can configure the maximum file size limit in the application’s properties file by setting the spring.servlet.multipart.max-file-size and spring.servlet.multipart.max-request-size properties to appropriate values. Additionally, you can use the MultipartFile parameter in the controller method to receive the uploaded file and process it as needed.

213
Q

What is the purpose of Spring Boot Actuator endpoints?

A

Spring Boot Actuator endpoints provide insights into the internals of a Spring Boot application such as health status, metrics, environment information, and more. These endpoints expose management and monitoring capabilities over HTTP or other protocols, allowing you to monitor and manage the application in production. Actuator endpoints can be customized and secured based on the specific requirements of the application.

214
Q

Explain the concept of Spring Boot Actuator metrics and monitoring.

A

Spring Boot Actuator metrics allow you to collect and monitor various application metrics such as HTTP request counts, response times, JVM memory usage, and database connection pool metrics.

Actuator metrics are collected by integrating with metrics libraries like Micrometer and can be exposed through various endpoints such as /actuator/metrics. These metrics can be visualized using monitoring tools like Prometheus, Grafana, or the built-in Actuator endpoints.

215
Q

How can you implement microservices architecture using Spring Boot?

A

Advanced Question 12

https://www.turing.com/interview-questions/spring-boot

216
Q

Describe the role of the Spring Cloud Netflix stack in a Spring Boot application.

A

The Spring Cloud Netflix stack provides integration with various Netflix OSS components to simplify the development of distributed systems in a Spring Boot application. It includes modules like Eureka for service discovery, Ribbon for client-side load balancing, Hystrix for fault tolerance, and Zuul for API gateway functionality.
These components enable developers to build scalable and resilient microservices architectures by providing out-of-the-box solutions for common distributed system challenges.

217
Q

What is the purpose of Spring Boot DevTools and how does it enhance development productivity?

A

Spring Boot DevTools is a set of developer tools that enhance the development experience for Spring Boot applications. It provides features like automatic application restart on code changes, live reloading of static resources, and enhanced logging during development.

DevTools helps in reducing the development turnaround time by eliminating the need for manual restarts and providing quick feedback on code changes.

218
Q

How can you implement distributed tracing in a Spring Boot application using Spring Cloud Sleuth?

A

To implement distributed tracing in a Spring Boot application with Spring Cloud Sleuth, you can include the necessary dependencies like spring-cloud-starter-sleuth. Sleuth integrates with popular distributed tracing systems like Zipkin or Jaeger.

Once configured, Sleuth automatically adds trace and span identifiers to the application’s logs and propagates them across different services. This allows you to trace the flow of requests across multiple services and analyze performance bottlenecks.

219
Q

Explain the concept of reactive programming in Spring Boot with Spring WebFlux.

A

Advanced Question 16

https://www.turing.com/interview-questions/spring-boot

220
Q

How does Spring Boot integrate with Apache Kafka for event-driven architectures?

A

Spring Boot provides integration with Apache Kafka through the Spring Kafka project. You can include the spring-boot-starter-kafka dependency to get started.

Spring Kafka provides abstractions to produce and consume messages from Kafka topics using the KafkaTemplate and @KafkaListener annotations, respectively. Additionally, Spring Kafka integrates with Spring Boot’s auto-configuration to simplify the configuration of Kafka-related properties.

221
Q

Describe the purpose and usage of Spring Boot’s caching abstraction.

A

Spring Boot’s caching abstraction provides a convenient way to cache the results of expensive operations, reducing the response time and improving application performance. By using annotations like @Cacheable, @CachePut, and @CacheEvict, you can easily cache method results based on specified cache names or keys.

The caching abstraction supports various cache providers, such as Redis or Ehcache, and can be easily configured using the application’s properties file.

222
Q

How can you perform database migrations in a Spring Boot application using Flyway or Liquibase?

A

Include corresponding dependencies (flyway-core or liquibase-core) to perform database migrations in a Spring Boot application using Flyway or Liquibase. By placing the migration scripts in the classpath (src/main/resources/db/migration), Flyway or Liquibase will automatically execute the scripts during application startup.

These migration scripts allow you to manage database schema changes, versioning, and data initialization in a controlled manner.

223
Q

Explain the concept of externalized configuration in Spring Boot and its benefits.

A

Externalized configuration in Spring Boot allows you to configure the application using external properties files, environment variables, or command-line arguments. This approach decouples the application configuration from the code, making it more flexible and easier to manage.

The externalized configuration enables the application to be deployed in different environments without modifying the code. Spring Boot provides a standardized and flexible way to read and use these external configurations.

224
Q

How can you implement distributed session management in a Spring Boot application using Spring Session?

A

Advanced Question 21

https://www.turing.com/interview-questions/spring-boot

225
Q

22.

How can you implement serverless functions using Spring Boot and AWS Lambda?

A

You can use the spring-cloud-function-adapter-aws dependency to implement serverless functions using Spring Boot and AWS Lambda. You can deploy Spring Boot applications as serverless functions on AWS Lambda by creating a function bean and configuring the AWS Lambda handler.

The adapter takes care of the integration between Spring Cloud Function and AWS Lambda, allowing you to develop serverless functions using the familiar Spring Boot programming model.

226
Q

How can you implement method-level security in a Spring Boot application?

A

Advanced Question 23

https://www.turing.com/interview-questions/spring-boot

227
Q

How can you implement server-sent events (SSE) in a Spring Boot application?

A

Advanced Question 24

https://www.turing.com/interview-questions/spring-boot

228
Q

How can you integrate Spring Boot with OAuth 2.0 for secure authentication and authorization?

A

You can use the Spring Security OAuth2 module to integrate Spring Boot with OAuth 2.0. By configuring the appropriate OAuth 2.0 provider details and defining the client registration properties, Spring Boot can handle the authentication and authorization flow.

You can secure your endpoints by applying Spring Security annotations like @PreAuthorize or by using declarative configuration. This integration enables secure authentication and authorization using OAuth 2.0 standards.

229
Q

How can you implement data caching in a Spring Boot application using the Spring Cache Abstraction?

A

Advanced Question 26

https://www.turing.com/interview-questions/spring-boot

230
Q

How can you configure a custom error page in a Spring Boot application?

A

Advanced Question 27

https://www.turing.com/interview-questions/spring-boot

231
Q

How can you implement distributed tracing in a Spring Boot application using OpenTelemetry?

A

To implement distributed tracing in a Spring Boot application using OpenTelemetry, you can include the necessary OpenTelemetry dependencies such as open telemetry-API and an OpenTelemetry exporter. Configuring the exporter lets you send trace data to a distributed tracing system like Jaeger or Zipkin.

OpenTelemetry automatically instructs the application to capture and propagate trace information across different services, allowing you to trace the execution path of requests in a distributed system.

232
Q

How can you implement asynchronous processing in a Spring Boot application?

A

Advanced Question 29

https://www.turing.com/interview-questions/spring-boot

233
Q

How can you enable HTTPS in a Spring Boot application?

A

Advanced Question 30

https://www.turing.com/interview-questions/spring-boot