I am working in Spring Boot, and in MyService class
I got a class name as String and i want to initialize that object and get back returned values.
but I have no much more idea about it, I think it achieved by Dependency injection. but, how ?
Suppose I have classes A.java, B.java, C.java
and Service class MyService.java
@Component
public class A{
public String wish(int timeHr){
//some logic of time based wish
return "Hello A"+" good morning";
}
}
@Component
public class B{
public String wish(int timeHr){
//some logic of time based wish
return "Hello B"+" good morning";
}
}
@Component
public class C{
public String wish(int timeHr){
//some logic of time based wish
return "Hello C"+" good morning";
}
}
@Service
public class MyService{
// i get here A class name as String like,
String classNameString = "A"; // or "B", or "C"
int timrHr = new Date().getHours();
//how to here i will initialize above class and get method wist(param) returned wish msg.
//like, a.wish(timeHr); and it gives "Hello A good morning"
}
I expect the output of returned by wish().
Can any one suggest me how do I achieved it ?
Thanks.