0% found this document useful (0 votes)
48 views

Spring_Boot_Complete_Interview_Questions

Spring Boot all interview qiestions tricky

Uploaded by

Prasad Mukherjee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Spring_Boot_Complete_Interview_Questions

Spring Boot all interview qiestions tricky

Uploaded by

Prasad Mukherjee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Spring Boot Hard and Tricky Interview Questions and Answers

1. How does Spring Boot auto-configuration work internally?

Answer: Spring Boot's auto-configuration works using the @EnableAutoConfiguration annotation.

Internally:

1. Auto-Configuration Classes: It scans META-INF/spring.factories files, which list all

auto-configuration classes under the key

org.springframework.boot.autoconfigure.EnableAutoConfiguration.

2. Conditional Annotations: Auto-configuration classes use conditional annotations like

@ConditionalOnClass, @ConditionalOnMissingBean, etc., to check if certain beans are already

present or missing in the context.

3. Custom Configuration: Developers can override beans or properties provided by

auto-configuration by defining them explicitly in their own configuration classes.

2. What is the difference between @SpringBootApplication and @EnableAutoConfiguration?

Answer:

- @SpringBootApplication is a convenience annotation that combines:

- @Configuration (for Java-based configuration),

- @EnableAutoConfiguration (enables auto-configuration), and

- @ComponentScan (scans for beans in the package and sub-packages).

- @EnableAutoConfiguration alone only enables the auto-configuration mechanism without

scanning components or adding explicit configurations.

Use @SpringBootApplication for most use cases as it is more concise.

3. How does Spring Boot manage externalized configurations?

Answer: Spring Boot uses the Spring Environment abstraction to manage externalized
configurations. It loads properties in the following order of precedence:

1. Command-line arguments.

2. application.properties or application.yml files (e.g., in src/main/resources).

3. Environment variables.

4. System properties.

5. Default properties (defined programmatically).

4. What is the role of Spring Boot Starter dependencies?

Answer: Spring Boot Starter dependencies simplify dependency management by bundling

commonly used libraries together. Examples include:

- spring-boot-starter-web: Includes Spring MVC, Jackson, and Tomcat for web applications.

- spring-boot-starter-data-jpa: Includes Hibernate, Spring Data JPA, and a database driver.

5. How does Spring Boot handle circular dependencies?

Answer: Spring Boot resolves circular dependencies using proxy beans or lazy initialization:

1. Proxy Beans: For @Autowired dependencies, Spring creates a proxy reference to delay

initialization until required.

2. @Lazy Annotation: Annotate one of the beans with @Lazy to postpone initialization.

3. Avoidance: Refactor code to remove circular dependencies, as they indicate poor design.

You might also like