java - REST API Autowire remote or local implementation of a service automatically -
i have rest api built on spring boot consisting of 2 seperate web services. don't know if 2 web services hosted on same machine want make remote , local implementation services. example below:
local service implementation:
public class localexampleservice implements exampleservice{ public item getitem(long id){ //get item using implementation local project } }
remote service implementation:
public class remoteexampleservice implements exampleservice{ @value("${serviceurl}") private string serviceurl; public item getitem(long id){ //get item calling remote service } }
controller:
public class mycontroller{ @autowired private exampleservice exampleservice; }
web service has many services local , remote implementation , want let spring know type of implementation should choose services.
i've been thinking putting url in properties file , during intialization app check whether properties contain url , autowire service approprietly. have write logic every service autowiring.
what's best option autowire correct service implementation automatically?
my attempt implement https://github.com/stanislavlapitsky/springsoaproxy
the idea check if spring bean cannot found locally automatically create proxy uses resttemplate internally call same service remotely.
you need define contract - services interfaces plus dto , define url resolver specify url should used each service.
Comments
Post a Comment