Interview Questions To: Crack Technical Interviews
Interview Questions To: Crack Technical Interviews
Interview Questions To: Crack Technical Interviews
www.bosscoderacademy.com 1
Q 1. Explain the role of Spring Boot in
microservices architecture.
www.bosscoderacademy.com 2
Discuss the significance of Spring Boot's
Q 3. actuator module in production
environments.
www.bosscoderacademy.com 3
Q 5. What are Spring Boot starters and how do
they simplify dependency management?
www.bosscoderacademy.com 4
Q 6. How do you create a simple RESTful web
service using Spring Boot?
java
@RestController
@RequestMapping("/api")
@GetMapping("/hello")
www.bosscoderacademy.com 5
Q 7. How do you connect a Spring Boot
application to a MySQL database?
properties
spring.datasource.url=jdbc:mysql://localhost:3306/
mydb
spring.datasource.username=root
spring.datasource.password=secret
spring.jpa.hibernate.ddl-auto=update
java
@Entity
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
www.bosscoderacademy.com 6
// getters and setters
Q 8.
How do you handle exceptions globally
java
@ControllerAdvice
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<String>
handleResourceNotFound(ResourceNotFoundException
ex) {
www.bosscoderacademy.com 7
@ExceptionHandler(Exception.class)
public ResponseEntity<String>
handleGeneralException(Exception ex) {
Q 9.
How do you use Spring Boot DevTools to
enhance the development experience?
xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
www.bosscoderacademy.com 8
Q 10.
How do you configure a custom endpoint
in Spring Boot Actuator?
java
@Component
@ReadOperation
properties
management.endpoints.web.exposure.include=custom
www.bosscoderacademy.com 9
Q 11.
How do you implement pagination and
sorting in a Spring Boot application?
java
java
@GetMapping("/users")
return userRepository.findAll(pageable);
www.bosscoderacademy.com 10
How do you implement pagination and
Q 12.
sorting in a Spring Boot application?
java
java
@GetMapping("/users")
return userRepository.findAll(pageable);
www.bosscoderacademy.com 11
Q 13.
How do you configure and use a custom
banner in a Spring Boot application?
Q 14.
How do you integrate Spring Boot with
Kafka?
xml
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
www.bosscoderacademy.com 12
xml
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=my-group
java
@Bean
www.bosscoderacademy.com 13
Q 15. How do you schedule tasks in Spring Boot?
java
@SpringBootApplication
@EnableScheduling
SpringApplication.run(MyApplication.class, args);
@Component
@Scheduled(fixedRate = 5000)
www.bosscoderacademy.com 14
Q 16.
How do you configure a Spring Boot
application to use Spring Security?
java
@Configuration
@EnableWebSecurity
@Override
http
.authorizeRequests()
.antMatchers("/public/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll()
.and()
.logout().permitAll();
www.bosscoderacademy.com 15
Q 17.
How do you implement caching in a Spring
Boot application?
java
@SpringBootApplication
@EnableCaching
SpringApplication.run(MyApplication.class,
args);
@Service
@Cacheable("users")
return userRepository.findById(id).orElse(null);
www.bosscoderacademy.com 16
properties
spring.cache.type=simple
Q 18.
How do you implement caching in a Spring
Boot application?
java
spring.mail.host=smtp.example.com
spring.mail.port=587
spring.mail.username=myusername
spring.mail.password=mypassword
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
www.bosscoderacademy.com 17
java
@Service
@Autowired
SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(text);
mailSender.send(message);
www.bosscoderacademy.com 18
Q 19.
How do you implement internationalization
(i18n) in a Spring Boot application?
properties
spring.messages.basename=messages
spring.messages.encoding=UTF-8
java
@RestController
@Autowired
@GetMapping("/greet")
return messageSource.getMessage("greeting",
null, locale);
www.bosscoderacademy.com 19
Q 20.
How do you integrate a third-party library
(like Lombok) in a Spring Boot application?
xml
<dependency>
<groupId>org.projectlombok</
groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
java
@Data
@Entity
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
www.bosscoderacademy.com 20
How do you create a custom validator in
Q 21.
Spring Boot?
java
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = CustomValidator.class)
@Documented
@Override
www.bosscoderacademy.com 21
@Override
java
@CustomConstraint
www.bosscoderacademy.com 22
Why
Bosscoder?
1000+ Alumni placed at Top
Product-based companies.
Explore More