Spring Cloud - 27. Micro Service간 통신
목차 Spring Cloud - 30. Micro Service간 통신 ErrorDecoder 구현 Spring Cloud - 29. Micro Service간 통신 Feign client 예외 처리 Spring Cloud - 28. Micro Service간 통신 Feign client Spring Cloud - 27. Micro Service간 통신 User Service@SpringBootApplication@EnableDiscoveryClient@Slf4jpublic class UserServiceApplication { public static void main(String[] args){ SpringApplication.run(UserServiceApplication.class, args); } @Bean public BCryptPasswordEncoder passwordEncoder() throws UnknownHostException { return new BCryptPasswordEncoder(); } @Bean public RestTemplate getRestTemplate(){ return new RestTemplate(); }} @Overridepublic UserDto getUserByUserId(String userId) { UserEntity userEntity = userRepository.findByUserId(userId); if (userEntity == null) throw new UsernameNotFoundException("User not found"); UserDto userDto = new ModelMapper().map(userEntity, UserDto.class); // List<ResponseOrder> orders = new ArrayList<>(); // userDto.setOrders(orders); String orderUrl = String.format(env.getProperty("order_service.url"), userId); ResponseEntity<List<ResponseOrder>> orderListResponse = restTemplate.exchange(orderUrl , HttpMethod.GET , null , new ParameterizedTypeReference<List<ResponseOrder>>() {}); List<ResponseOrder> orderList = orderListResponse.getBody(); userDto.setOrders(orderList); return userDto;} application.ymltoken: expiration_time: 84600000 secret: user_token_native_application_changedgateway: ip: 192.168.123.106order_service: url: http://127.0.0.1:8080/order-service/%s/orders token: expiration_time: 84600000 secret: user_token_native_application_changedgateway: ip: 192.168.123.106order_service: url: http://ORDER-SERVICE/order-service/%s/orders @SpringBootApplication@EnableDiscoveryClient@Slf4jpublic class UserServiceApplication { public static void main(String[] args){ SpringApplication.run(UserServiceApplication.class, args); } @Bean public BCryptPasswordEncoder passwordEncoder() throws UnknownHostException { return new BCryptPasswordEncoder(); } @Bean @LoadBalanced public RestTemplate getRestTemplate(){ return new RestTemplate(); }}