I have an interface IpersonService with 2 implementation
public Interface IPersonService {
public List<Person> readPersons();
}
@Service
public class FilePersonService implements IPersonService {
public List<Person> readPersons(){
//read from File
}
}
and
@Service
public class DbPersonServiceimplements ICaseService{
@Autowired
PersonRepository repository
public List<Person> readPersons(){
//read from database
return repository.findAll()
}
}
From my controller, i would like to Autowire a ICaseService depending of a value read from application.properties files.
@RestController
public class Personcontroler {
@Value("${database.type}")
String dbType;
@Autowired
IpersonService personService;
@GetMapping("/persons")
public List<Person> readAllPersons(){
//the person service instance depend of the dbType read from application.properties file
return personService.readPersons()
}
}
so depending on thr config value, i would like to have either a FilePersonService , or a DbPersonService.
How can i achive it please?
thanks so much