IndexController.java
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.glsx.api.controller;
import com.glsx.api.remote.IndexFeignClient;
import com.glsx.biz.user.common.entity.User;
import com.glsx.biz.user.service.UserService;
import com.glsx.cloudframework.exception.ServiceException;
import com.glsx.plat.core.web.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @Title: IndexController.java
* @Description: 远程服务调用demo
* @author think.wang
* @version V1.0
* @Company: Didihu.com.cn
* @Copyright Copyright (c) 2017
*/
@RestController
public class IndexController {
@Autowired
private IndexFeignClient indexFeignClient;
@DubboReference(version = "1.0.0")
private UserService userService;
@ResponseBody
@RequestMapping("home")
public R home(){
try {
User user = userService.getByUserId(92001768); //dubbo服务调用
return R.ok().data(user);
} catch (ServiceException e) {
e.printStackTrace();
}
return R.ok().data(indexFeignClient.getHome()); //feign调用远程服务
}
}