package com.example.pc_spring_rest_client;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class PcSpringRestClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(PcSpringRestClientApplication.class, args);
    }

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    @Bean
    public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
        return args -> {
            TimeInfo timeInfo = restTemplate
                    .getForObject(
                    "http://217.182.72.251:8080/xmpl_rest/now", TimeInfo.class);
            System.out.println(timeInfo);
        };
    }

}
