0% found this document useful (0 votes)
102 views2 pages

Master Java Interview Scenarios With Answers

The document presents a scenario-based question regarding bean injection conflicts in Spring Boot, specifically when two beans implement the same interface. It provides a simple example of an EmailNotificationService and suggests using profiles or a factory to inject the correct service in a multi-tenant application. The document also raises follow-up questions about testing this behavior and handling runtime tenant configuration changes.

Uploaded by

Harsh Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views2 pages

Master Java Interview Scenarios With Answers

The document presents a scenario-based question regarding bean injection conflicts in Spring Boot, specifically when two beans implement the same interface. It provides a simple example of an EmailNotificationService and suggests using profiles or a factory to inject the correct service in a multi-tenant application. The document also raises follow-up questions about testing this behavior and handling runtime tenant configuration changes.

Uploaded by

Harsh Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q1.

■ Scenario-Based Question: Bean Injection Conflict in Spring Boot


■■■ Interviewer:
You’ve created two beans implementing the same interface. Spring injects the wrong one. Why?

■ Answer:
■ Simple Example:
@Component("emailService")
public class EmailNotificationService implements NotificationService { ... }

■ Enterprise Example:
In a multi-tenant app, inject the correct NotificationService based on tenant type using profiles/factory.

■ Follow-up: How to test this behavior? What if tenant config changes at runtime?
Tags: #SpringBoot #DependencyInjection #MultiTenant

Q2. ■ Scenario-Based Question: Bean Injection Conflict in Spring Boot


■■■ Interviewer:
You’ve created two beans implementing the same interface. Spring injects the wrong one. Why?

■ Answer:
■ Simple Example:
@Component("emailService")
public class EmailNotificationService implements NotificationService { ... }

■ Enterprise Example:
In a multi-tenant app, inject the correct NotificationService based on tenant type using profiles/factory.

■ Follow-up: How to test this behavior? What if tenant config changes at runtime?
Tags: #SpringBoot #DependencyInjection #MultiTenant

Q3. ■ Scenario-Based Question: Bean Injection Conflict in Spring Boot


■■■ Interviewer:
You’ve created two beans implementing the same interface. Spring injects the wrong one. Why?

■ Answer:
■ Simple Example:
@Component("emailService")
public class EmailNotificationService implements NotificationService { ... }

■ Enterprise Example:
In a multi-tenant app, inject the correct NotificationService based on tenant type using profiles/factory.

■ Follow-up: How to test this behavior? What if tenant config changes at runtime?
Tags: #SpringBoot #DependencyInjection #MultiTenant
Q4. ■ Scenario-Based Question: Bean Injection Conflict in Spring Boot
■■■ Interviewer:
You’ve created two beans implementing the same interface. Spring injects the wrong one. Why?

■ Answer:
■ Simple Example:
@Component("emailService")
public class EmailNotificationService implements NotificationService { ... }

■ Enterprise Example:
In a multi-tenant app, inject the correct NotificationService based on tenant type using profiles/factory.

■ Follow-up: How to test this behavior? What if tenant config changes at runtime?
Tags: #SpringBoot #DependencyInjection #MultiTenant

Q5. ■ Scenario-Based Question: Bean Injection Conflict in Spring Boot


■■■ Interviewer:
You’ve created two beans implementing the same interface. Spring injects the wrong one. Why?

■ Answer:
■ Simple Example:
@Component("emailService")
public class EmailNotificationService implements NotificationService { ... }

■ Enterprise Example:
In a multi-tenant app, inject the correct NotificationService based on tenant type using profiles/factory.

■ Follow-up: How to test this behavior? What if tenant config changes at runtime?
Tags: #SpringBoot #DependencyInjection #MultiTenant

You might also like