Frequently Asked Spring Framework Interview Questions 2022

Spring Boot

Spring Framework or Spring is a lightweight application framework for developing Enterprise Java Application.

The two most popular features that Spring framework offers are

  • Dependency Injection (IOC)
  • Aspect Oriented Programming (AOP)
Sping Boot

Spring framework modules

Spring Framework is categorized based on the main features as:

  • Core Container
  • Data Access/Integration
  • Web
  • Aspect Oriented Programming (AOP)
  • Instrumentation and Test

Advantages of Spring Framework :

  • Spring Framework is Lightweight
  • It is Loosely coupled using dependency injection.
  • Spring Framework Provides pre-defined templates for JDBC, Hibernate, JPA, etc. and good integration with other frameworks.
  • Thanks to Dependency Injection, these applications are easy to test.
  • Spring Framework Offers powerful abstraction to Java EE specifications such as JMS, JDBC, JPA, and JTA.
  • Provides declarative support for caching, validation, transactions, and formatting.
  • Offers flexibilityto configure beans in multiple ways such as XML, Annotations, and JavaConfig.
  • Reduces Duplication of code.

Features of Spring Framework

  • Create stand-alone Spring applications
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  • Provide opinionated ‘starter’ dependencies to simplify your build configuration
  • Automatically configure Spring and 3rd party libraries whenever possible
  • Provide production-ready features such as metrics, health checks, and externalized configuration
  • Absolutely no code generation and no requirement for XML configuration

Spring Framework allows you to build stand-alone, operating, production-grade Spring based Applications with ease.

Spring Boot Framework contains the following:

  • is an opinionated framework
  • is based on convention over configuration
  • can build stand-alone applications
  • can create production ready package
  • has Embedded Tomcat server

To summarize, Spring Boot Framework is a pre-configured, pre-sugared set of technologies/framework to minimize boiler plate configuration offering the quickest way to get a Spring web application ready and operational with minimal configuration/coding out-of-the-box.

Spring Framework MCQs Questions

1.Which Spring annotation can be used to expose a controller as REST API?

@Controller
None of the options
@RestAPIController
@RestController
Answer- @RestController
2.@RequestMapping(value = “/hospitals/{id}”, method = RequestMethod.GET) How to get the value of id in controller method?

@Variable(“id”)
@PathVariable(“id”)
None of the options
@RequestVariable(“id”)
@RequestMapping(“id�)
Answer- @PathVariable(“id”)
3.Which is the class that has to be autowired with the controller class for invoking processes?

Model
Entity
None of the options
Service
Any of the options
Answer- Service
4.Spring Boot Microservices are loosly coupled, independent, constrained and abstracted.

True
False
Answer- False

Spring Framework Database Integration – Quiz

1.__ can be used to over a SQL as well as NoSQL database.

Spring JPA
None of the options
Spring Data
Spring JDBCTemplate
Answer- Spring Data
2.Which specification allows ORM over RDBMS?

Spring Persistence API
Spring ORM API
Java Persistence API
Java ORM API
Answer- Java Persistence API
3.Embedded database support has persistent data storage.

True
False
Answer- False
4.Embedded DB support is not available for _.

H2
Derby
HSQL
Oracle
Answer- Oracle
5.What is the dependency to be added to configure JPA to Spring Boot Project?

None of the options
Spring-boot-starter-data-jpa
Spring-boot-starter-jpa
Spring-boot-starter-data
Answer- Spring-boot-starter-data-jpa

Spring Framework Consuming REST Service – Quiz

1.What are the security techniques that can be used for Spring Boot Microservices?

Oauth
HTTP Digest
None of the options
HTTP Basic
All the options
Answer- All the options
2.Spring Boot offers __ template to consume REST Services.

RestTemplate
MockMVC
RestMVC
None of the options
Answer- RestTemplate
3.In Basic authentication, username and password are

base64 encoded
base16 encoded
sha256 hashed
RSA encrypted
Answer- base64 encoded
4.Which is the correct format for HTTP Basic security technique?

Authorization: dm9yZGVsOnZvcmRlbA==
None of the options
Authorization: Basic dm9yZGVsOnZvcmRlbA==
Answer- Authorization: Basic dm9yZGVsOnZvcmRlbA==
5.Which is not a valid method in RestTemplate to get http request?

getForObject
getForEntity
None of the options
getForLocation
Answer- getForLocation

Spring Framework Testing – Quiz

1.Which is the class level annotation that is used to test Repository class?

@DataJpaTest
@JpaTest
All the options
@DataTest
None of the options
Answer- @DataJpaTest
2._ class has to be auto wired to the Repository test class to test Repository class.

None of the options
TestDataEntity
Both the options
TestEntityManager
Answer- TestEntityManager
3.Which annotation can be used to run quick unit tests?

@SpringBootTest
@IntTest
@IntegrateTest
@SpringTest
Answer- @SpringBootTest
4.In Spring Boot, unit testing can be done on __ class.

None of the options
Repository
Service
Controller
All the options
Answer- All the options
5.What is the technique used to do unit testing on a Controller class?

TestMvc
None of the options
RestMvc
All the options
MockMvc
Answer- MockMvc

Spring Boot – Final Assessment

1.What are the template engine/engines that is/are not supported by Spring Boot?

FreeMarker
Thymeleaf
Groovy
None of the options
All the options
Answer- All the options
2.Which is the Spring Boot starter that has to be added to include Thymeleaf template engine?

spring-boot-starter-thymeleaf
None of the options
Spring-boot-thymeleaf-starter
Spring-boot-thymeleaf
Answer- spring-boot-starter-thymeleaf
3.Which is the UI Web framework that is built to use Spring Boot?

Bootstrap
None of the options
HTML KickStart.
Vaadin
SproutCore
Answer- Vaadin
4.Http method Patch is used to _.

Add a new entity
Update an entity
Delete an entity
Modify an entity
None of the options
Answer- Modify an entity
5.Which is not a valid Cache provider supported by Spring Boot?

Couchbase
EhCache 2.x
None of the options
Redis
Hazelcast
Answer- None of the options
6.Integration testing can be done using _.

TestRestTemplate
MvcTest
TestTemplate
MockMvc
Answer- TestRestTemplate
7.Which is the Spring Boot annotation used for caching auto configuration?

@Cache
None of the options
@Cacheable
@CacheEnabled
Answer- @Cacheable
8.Which is not a valid method in RestTemplate to http post request?

postForObject
None of the options
postForLocation
Both the options
Answer- None of the options
9.Any configuration on Logback logging has to be done in __ in Spring Framework

either application.properties or application.yml
None of the options
application.properties
application.yml
Answer- application.properties
10.This authentication/Authorization mechanism helps to access resource through third party resources.

HTTP Basic
None of the options
X509
Oauth
Answer- Oauth
11.Which is the default logging file in springboot?

logback
log.log
logback.log
spring.log
Answer- logback
12.What are the template engine/engines that is/are not supported by Spring Boot?

Groovy
Thymeleaf
None of the options
All the options
FreeMarker
Answer- None of the options
13.Repository class has to extend __ class to get the implementation benefit of Spring Data.

CrudRepository
CrudRep
No Class needs to extended
CrudRepositoryTest
Answer- CrudRepository
14.What is the Spring Boot starter that has to be added for logging?

Spring-boot-logging-starter
None of the options
Spring-boot-logging
spring-boot-starter-logging
Answer- spring-boot-starter-logging
15.What is the annotation to be added for Entity class?

@Entity
None of the options
@JPAEntity
@DataEntity
Answer- @Entity
16.What are the HTTP methods that cannot be implemented in Spring Boot Rest Service?

Del
Get
Patch
Post
Put
Answer- Patch
17.Service class added to Rest API should be annotated as _.

Any of the options
@RestAPIService
@Service
@RestService
None of the options
Answer- @Service
18.Which is the Spring boot starter that has to be added to include Freemarker template engine?

None of the options
Spring-boot-freemarker
spring-boot-starter-freemarker
Spring-boot-freemarker-starter
Answer- spring-boot-starter-freemarker
19.While implementing security, you need to add AuthenticationEntryPoint class to extend _ class.

AuthenticationEntry
BasicAuthentication
None of the options
BasicAuthenticationEntryPoint
Answer- BasicAuthenticationEntryPoint
20.Which is the dependency to be added to include basic security to the project?

Spring-boot-security
None of the options
spring-boot-starter-security
spring-starter-security
Answer- spring-boot-starter-security
21.What is the method name to fetch all data for a entity from database in Repository class?

None of the options
findAllItems()
findAll()
getAll()
Answer- findAll()
22.__ class does magic in Spring Data Integration implementation in Spring Framework

Service
JPARepository
CrudRepository
Repo
Answer- Repo
23.Service class added to Rest API should be annotated as _.

None of the options
@Service
Any of the options
@RestService
@RestAPIService
Answer- @Service
24.Which is the Spring Boot annotation used for caching auto configuration?

None of the options
@Cache
@CacheEnabled
@Cacheable
Answer- @CacheEnabled
25.Which mechanism can be used to secure basic http or http digest authentications?

None of the options
Oath2
SSL/TLS encryption
Controller Based Authentication
Answer- SSL/TLS encryption
26.Spring boot uses _ by default for logging.

Loopback
Logger
None of the options
Logback
Answer- Logback
27.Annotation @PathVariable is used to _.

None of the options
Map an entity
Map a path URI
Map an input param
Answer-Map an input param
28.What are the Rest Template methods that can be used to handle any kind of request type?

None of the options
execute
exchange
Both the options
Answer- Both the options

List of Fresco Play Courses without Hands-On | Fresco Play
HMTL5 Semantics Elements MCQs Answers | Fresco Play
HMTL5 Semantics Elements Hands-On Solutions | Fresco Play
Styling with CSS3 Hands-On Solutions | Fresco Play
Blockchain Intermedio MCQs Answers | Fresco Play
Blockchain – Potentes Nexus MCQs Answers | Fresco Play
Azure Essentials MCQs Answers | Fresco Play
AWS Essentials MCQs Answers | Fresco Play

About Author


After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.