i use spring resttemplate consume other services in local environment.
in production env scalabilty want use service registry eureka , ribbon client.
i want have clean separation of code eureka , ribbon client can run services locally without overhead of running separate service eureka , registering services eureka , doing lookup against eureka during orchestration.
i have used spring profile feature separate out code , configuration related local , production.
i stuck @ 1 point use resttemplate invoke other services.
i want use load balanced rest template prod env , normal rest template local service call.
i having difficulty in injecting type of resttemplate based on environment.
can me right way of injecting resttemplate services can run locally leverage service registry , ribbon client when running in prod env without impacting code.
thanks, sri
profiles
use @profile
annotation on resttemplate bean.
example:
@configuration public class config { @profile("local") @bean public resttemplate resttemplatelocal(){ return new resttemplate(); } @profile("production") @loadbalanced @bean public resttemplate resttemplateproduction(){ return new resttemplate(); } }
then can autowire bean wherever need , based on active profile
, return either normal or loadbalanced resttemplate.
@autowired private resttemplate resttemplate;
Comments
Post a Comment