飞滴出行网约车2022-api-boss通过feign远程调用service-driver-user实现司机用户信息新增

master
yh 3 years ago
parent 53b069d0d9
commit b35acd6040

@ -20,6 +20,15 @@
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- feign 组件 基于 loadbalancer 依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -2,8 +2,12 @@ package com.mashibing.apiboss;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ApiBossApplication { public class ApiBossApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ApiBossApplication.class); SpringApplication.run(ApiBossApplication.class);

@ -0,0 +1,23 @@
package com.mashibing.apiboss.controller;
import com.mashibing.apiboss.service.UserService;
import com.mashibing.internalcommon.dto.DriverUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DriverUserController {
@Autowired
private UserService service;
@PostMapping("/driver-user")
public ResponseResult saveDriverUser(@RequestBody DriverUser driverUser){
return service.saveDriverUser(driverUser);
}
}

@ -0,0 +1,17 @@
package com.mashibing.apiboss.remote;
import com.mashibing.internalcommon.dto.DriverUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@Service
@FeignClient("service-driver-user")
public interface ServiceDriverUserClient {
@PostMapping("/user")
public ResponseResult saveUser(@RequestBody DriverUser driverUser);
}

@ -0,0 +1,20 @@
package com.mashibing.apiboss.service;
import com.mashibing.apiboss.remote.ServiceDriverUserClient;
import com.mashibing.internalcommon.dto.DriverUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private ServiceDriverUserClient client;
public ResponseResult saveDriverUser(DriverUser driverUser){
return client.saveUser(driverUser);
}
}
Loading…
Cancel
Save