mardi 24 février 2015

Spring service implementation by environment property

I have a service interface



interface ImageSearchService {
// methods...
}


And I have 2 implementations:



@Service
class GoogleImageSearchImpl implements ImageSearchService {
// methods...
}

@Service
class AzureImageSearchImpl implements ImageSearchService {
// methods...
}


And I have a controller to use one of the both:



@Controller
ImageSearchController {

@Autowired
ImageSearchService imageSearch; // Google or Azure ?!?

}


How can I use a Environment API to set the right one implementation?


If environment property is my.search.impl=google spring needs to use GoogleImageSearchImpl, or if environment my.search.impl=google spring needs to use AzureImageSearchImpl.


Aucun commentaire:

Enregistrer un commentaire