http服務 發佈到平臺後能夠直接使用 http 請求來調用,注意發佈服務時選擇 非 tars 協議!spring
1,建立一個 springboot 項目,並在啓動類添加 @EnableTarsServer 註解springboot
@SpringBootApplication @EnableTarsServer public class TarsSpringbootHttpServerApplication { public static void main(String[] args) { SpringApplication.run(TarsSpringbootHttpServerApplication.class, args); } }
2,POM 依賴, 和非 http 依賴一致app
3,編寫 controllertcp
@TarsHttpService("HttpObj") : 表示是一個 http 服務並指明 obj 名稱
也能夠調用別的 tars 服務(能夠註解自動注入也能夠構建通訊器)
@TarsHttpService("HttpObj") @RestController public class TestController { @RequestMapping("/test") public String test() { return "success"; } @RequestMapping("/test1") public String test1() { CommunicatorConfig cfg = new CommunicatorConfig(); Communicator communicator = CommunicatorFactory.getInstance().getCommunicator(cfg); GlobalIdPrx proxy = communicator.stringToProxy(GlobalIdPrx.class, "ICTPAAS.GlobalId.GlobalIdObj@tcp -h 203.195.235.113 -p 30001"); String globalId = proxy.getGlobalId("qqqqq"); return globalId; } }
4,測試測試