Tech Interview Questions
171 subscribers
18 photos
1 file
67 links
Download Telegram
How does Spring Boot auto-configuration work?

Answer:

Spring Boot uses the @EnableAutoConfiguration annotation (or indirectly via @SpringBootApplication) to configure beans based on the libraries on the classpath and properties defined in application.properties or application.yml.

The spring.factories file inside META-INF lists all the auto-configuration classes, which are conditionally applied using @ConditionalOnClass, @ConditionalOnProperty, etc.
What is the difference between @Component, @Repository, and @Service?

Answer:

@Component: A generic stereotype annotation for any Spring-managed component.

@Repository: A specialization of @Component used to indicate a Data Access Object (DAO). Automatically translates database exceptions into Spring exceptions.

@Service: A specialization of @Component used to indicate a service layer bean. It is used to encapsulate business logic.
How does Spring Boot handle exceptions in REST APIs?

Answer:

Use @ControllerAdvice to define a global exception handler.

Handle exceptions with @ExceptionHandler methods in the advice class.

Return meaningful HTTP status codes and error messages in the response body.
What is the purpose of the @SpringBootApplication annotation?

Answer:

It is a combination of three annotations:

1. @SpringBootConfiguration: Similar to @Configuration.


2. @EnableAutoConfiguration: Enables Spring Boot's auto-configuration.


3. @ComponentScan: Scans the package where the application class resides.
What is the use of @Conditional annotations in Spring Boot?

Answer:

Spring Boot uses @Conditional annotations to enable conditional bean creation.

Examples:

@ConditionalOnClass: Bean is created only if a specific class is on the classpath.

@ConditionalOnProperty: Bean is created only if a specific property is defined in the configuration.
๐Ÿ”ฅ3
Forwarded from Java Express
Today's demo session will cover Spring Boot features, and the trainer will conduct a quiz on Spring Boot basics and its key features. Don't miss it! ๐Ÿš€

๐Ÿ”ฅ Spring Boot & Microservices
๐Ÿ”ฅ Real Time Java Project
๐Ÿ‘จโ€โœˆ๏ธ Trainer : Mr. Bhaskar

Day 3 : 20th Feb @ 9 OM IST
๐Ÿ‘‰ Enroll Now for Meeting Details : https://bit.ly/4gyBoIV

๐Ÿ“ž Join In WhatsApp : https://bit.ly/3Rbgvd1

Back Up Videos
Day 1 : https://youtu.be/TgPi69_iGRg
Day 2 : https://youtu.be/XEPQpuqBCAM
โšก๏ธโšก๏ธWhat are Spring Boot Starters?โšก๏ธโšก๏ธ

Answer:
Spring Boot
Starters are pre-configured dependency packs that simplify project setup.
โ€ข Example Starters:
โ€ข
spring-boot-starter-web โ†’ For web applications
โ€ข
spring-boot-starter-data-jpa โ†’ For JPA and Hibernate
โ€ข
spring-boot-starter-security โ†’ For Spring Security

Example (Maven Dependency for Spring Boot Web Starter):

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ”ก๐Ÿ”กWhat is Spring Boot Actuator?

Answer:
Spring Boot
Actuator provides monitoring and management features for applications.
โ€ข It exposes endpoints like:
โ€ข
/actuator/health โ†’ Checks application health
โ€ข
/actuator/metrics โ†’ Shows performance metrics
โ€ข
/actuator/env โ†’ Displays environment properties

Enable Actuator in application.properties:

management.endpoints.web.exposure.include=health,metrics,info
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘1
๐Ÿ”ก What are Embedded Servers in Spring Boot?

Answer:
Spring Boot includes
embedded servers like Tomcat, Jetty, and Undertow, eliminating the need for external deployment.
โ€ข By default, Spring Boot uses
Tomcat (spring-boot-starter-web).
โ€ข You can switch to
Jetty:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<scope>provided</scope>
</dependency>


โ€ข Server configuration can be customized in application.properties:

server.port=8081
server.tomcat.threads.max=200
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ”ก How do you customize logging in Spring Boot?

Answer:
Spring Boot uses
Logback by default but supports SLF4J, Log4j2, and Java Util Logging.

Customize Logging in application.properties:

logging.level.org.springframework=DEBUG
logging.level.com.myapp=INFO
logging.file.name=app.log
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} - %msg%n
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘2
If youโ€™re enjoying these types of questions, please give a thumbs-up (๐Ÿ‘)!
๐Ÿ‘7๐Ÿ‘2๐Ÿ”ฅ1
Forwarded from Java Express Official
Hi Everyone,

๐Ÿ”ก๐Ÿ”ก๐Ÿ”ก๐Ÿ”ก๐Ÿ”ก๐Ÿ”ก๐Ÿ”ก๐Ÿ”ก
Exciting news! Our JavaExpress Android app is now officially available. Install it on your phone and watch videos anytime. Click the link below to download it from the Play Store!

โ˜„๏ธโ˜„๏ธโ˜„๏ธ
Link : https://play.google.com/store/apps/details?id=com.javaexpress
Please open Telegram to view this post
VIEW IN TELEGRAM