title: How to run @SpringBootApplication without controller
body: <p>How to run code from class with @SpringBootApplication annotation. I want to run my code without calling to controller and get info from terminal not web browser. I tried to call weatherService in @SpringBootApplication but I've got a application failed start with description </p>
  
  <pre><code>The dependencies of some of the beans in the application context form a cycle:
  
  ┌─────┐
  |  weatherClientApplication
  ↑     ↓
  |  weatherService defined in file [C:\Users\xxx\IdeaProjects\weatherclient\target\classes\com\xxx\restapiclient\service\WeatherService.class]
  └─────┘
  </code></pre>
  
  <pre><code>@SpringBootApplication
  public class WeatherClientApplication {
  
      private WeatherService weatherService;
  
      public WeatherClientApplication(WeatherService weatherService) {
          this.weatherService = weatherService;
      }
  
      private static final Logger log = LoggerFactory.getLogger(WeatherClientApplication.class);
  
      public static void main(String[] args) {
          SpringApplication.run(WeatherClientApplication.class, args);
      }
  
      @Bean
      public RestTemplate restTemplate(RestTemplateBuilder builder){
          return builder.build();
      }
  
  
      @Bean
      public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
          return args -&gt; {
              log.info(weatherService.getTemperatureByCityName("Krakow"));
          };
      }
  
  }
  </code></pre>
  
  <pre><code>@Service
  public class WeatherService {
  
      private RestTemplate restTemplate;
  
      public WeatherService(RestTemplate restTemplate) {
          this.restTemplate = restTemplate;
      }
  
      public String getTemperatureByCityName(String cityName) {
          String url = "http://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&amp;APPID=" + API_KEY + "&amp;units=metric";
          Quote quote = restTemplate.getForObject(url, Quote.class);
          return String.valueOf(quote.getMain().getTemp());
      }
  }
  </code></pre>