DEV Community

Okota Nick
Okota Nick

Posted on

How to inject subclass at runtime in Spring Boot

I am new to Spring Boot. I am writing a sample project to learn. I have a superclass service. I have two subclass services which extend superclass service. In RestController I want to dynamically use one of the subclass based on a if condition. Is it a good idea? Any better way to do that? I know that if else condition to use a concrete class is bad.

Top comments (1)

Collapse
 
okotanick profile image
Okota Nick

Found a good solution here w3spot.com/2022/04/how-to-dynamica.... Posting it for others. I liked the approach.