Spring MCQ Banner

Spring Multiple Choice Questions (MCQs) and Answers

Master Spring Framework with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Spring concepts. Begin your placement preparation journey now!

Q121

Q121 How does Spring Cloud support distributed tracing?

A

Using tracing annotations

B

Using Sleuth

C

Using AOP

D

Using HttpSecurity

Q122

Q122 Which component of Spring Cloud handles service registration and discovery?

A

Spring Cloud Gateway

B

Spring Boot Actuator

C

Eureka Server

D

Config Server

Q123

Q123 How can you centralize configuration in Spring Cloud?

A

Using Spring Cloud Gateway

B

Using Config Server

C

Using RestTemplate

D

Using HttpSecurity

Q124

Q124 How can you enable a Spring Boot application to act as a Eureka client?

A

Use @EnableEurekaClient annotation

B

Use @EnableDiscoveryClient annotation

C

Use @EnableConfigClient annotation

D

Use @EnableCloudConfig annotation

Q125

Q125 How do you create a custom Zuul filter in Spring Cloud?

A

Extend ZuulFilter class

B

Use @ZuulFilter annotation

C

Implement Filter interface

D

Use @EnableZuulProxy annotation

Q126

Q126 How do you implement circuit breaker functionality in Spring Cloud?

A

Use @CircuitBreaker annotation

B

Use @HystrixCommand annotation

C

Use @EnableCircuitBreaker annotation

D

Use @Fallback annotation

Q127

Q127 Why does a Spring Cloud Config client fail to fetch configurations?

A

Incorrect configuration location

B

Invalid credentials

C

Config server down

D

All of the above

Q128

Q128 Why does a "RibbonLoadBalancerClientException" occur in Spring Cloud?

A

Missing Eureka registration

B

Invalid load balancing rules

C

Service down

D

Any of the above

Q129

Q129 What is the primary use of @Configuration in Spring?

A

To define a Bean

B

To enable auto-configuration

C

To manage dependency injection

D

To create application context

Q130

Q130 How can you define multiple Beans in a single Java configuration file?

A

Use @Bean methods

B

Use multiple @Configuration classes

C

Use @Import annotation

D

Any of the above

Q131

Q131 What is the role of the @Import annotation in Spring configuration?

A

To import properties

B

To import XML configuration

C

To import another configuration class

D

To import Beans

Q132

Q132 Which annotation is used to customize the initialization and destruction of a Bean?

A

@Bean

B

@Scope

C

@PostConstruct and @PreDestroy

D

@Lifecycle

Q133

Q133 How do you define a prototype Bean in Spring Java configuration?

A

Use scope="prototype" in XML

B

Use @Scope("prototype") annotation

C

Use @Prototype annotation

D

Use @Bean with scope

Q134

Q134 How do you load properties in a Spring Java configuration class?

A

Use @ConfigurationProperties annotation

B

Use @Value annotation

C

Use Environment API

D

All of the above

Q135

Q135 Why does a "BeanDefinitionOverrideException" occur in Spring?

A

Circular dependency

B

Duplicate Bean definition

C

Invalid Bean scope

D

Improper initialization

Q136

Q136 Why does a "NoSuchBeanDefinitionException" occur during runtime?

A

Missing @Bean annotation

B

Improper configuration class

C

Invalid Bean scope

D

Any of the above

Q137

Q137 Which Spring feature can optimize Bean initialization?

A

Lazy initialization

B

Prototype scope

C

Singleton scope

D

ApplicationContext

Q138

Q138 How can you minimize memory usage in a Spring application?

A

Use prototype-scoped Beans

B

Use @Lazy annotation

C

Use singleton Beans with lazy initialization

D

Use all these methods

Q139

Q139 What is the purpose of the @Profile annotation in Spring?

A

To create Bean profiles

B

To define application profiles

C

To manage environment properties

D

To enable caching

Q140

Q140 How can you enable caching in a Spring application?

A

Use @EnableCaching annotation

B

Use @Cacheable annotation

C

Use CacheManager configuration

D

Use all these methods

Q141

Q141 How can you implement a custom cache in Spring?

A

Extend CacheManager

B

Use @CustomCache annotation

C

Implement Cache interface

D

Use @CacheConfig annotation

Q142

Q142 Why does a "CacheLookupException" occur in Spring?

A

Cache miss

B

Cache configuration error

C

Improper cache initialization

D

Invalid cache key

Q143

Q143 Why does a "BeanCurrentlyInCreationException" occur in Spring?

A

Circular dependency

B

Improper Bean initialization

C

Missing configuration

D

Invalid @Lazy usage

Q144

Q144 What is the primary benefit of using Spring in enterprise applications?

A

Simplified configuration

B

Improved modularity

C

Enhanced security

D

All of these

Q145

Q145 How does Spring support multi-threaded application development?

A

Using @Async annotation

B

Using ThreadPoolTaskExecutor

C

Using AOP

D

All of these

Q146

Q146 What is the role of Spring Boot in microservices architecture?

A

Dependency management

B

Centralized configuration

C

Simplified application startup

D

All of these

Q147

Q147 How can you implement logging in a Spring application?

A

Use Log4j

B

Use SLF4J

C

Use Spring Logging Framework

D

All of these

Q148

Q148 How do you test REST endpoints in a Spring application?

A

Use MockMvc

B

Use RestTemplate

C

Use Postman

D

Use JUnit

Q149

Q149 Why does a "LazyInitializationException" occur in Hibernate with Spring?

A

Session closed before use

B

Incorrect Bean scope

C

Invalid ORM mapping

D

Improper transaction configuration

Q150

Q150 An application fails with "TransactionRollbackException" in a Spring transaction. What is the likely cause?

A

Database constraint violation

B

Improper transaction boundary

C

Incorrect Bean configuration

D

All of these

ad verticalad vertical
ad