Example usage for org.springframework.boot CommandLineRunner CommandLineRunner

List of usage examples for org.springframework.boot CommandLineRunner CommandLineRunner

Introduction

In this page you can find the example usage for org.springframework.boot CommandLineRunner CommandLineRunner.

Prototype

CommandLineRunner

Source Link

Usage

From source file:com.tdmehmet.catalog.TdmehmetCatalogRestApplication.java

@Bean
CommandLineRunner init(final AccountRepository accountRepository) {

    return new CommandLineRunner() {

        @Override//from   w w w .java2 s .  c o  m
        public void run(String... arg0) throws Exception {
            accountRepository.save(new Account("usertest", "secret"));
        }
    };
}

From source file:com.cocktail.CocktailApplication.java

@Bean
CommandLineRunner init(final UserRepository userRepository) {

    return new CommandLineRunner() {

        @Override/*  www . j a  va  2 s .c  o m*/
        public void run(String... arg0) throws Exception {
            userRepository.save(new User("adelgo", "adelgo"));
            userRepository.save(new User("youssef", "youssef"));
        }

    };
}

From source file:org.openwms.tms.routing.RoutingServiceRunner.java

@Bean
public CommandLineRunner init(final ActionRepository repo, final RouteRepository routeRepository) {

    return new CommandLineRunner() {
        @Override/*www.  jav  a2s. c om*/
        public void run(String... strings) throws Exception {
            Route routeDEF = routeRepository.save(Route.DEF_ROUTE);
            Route routeNO = routeRepository.save(Route.NO_ROUTE);
            Route route1 = routeRepository.save(new Route("R001"));
            repo.save(new Action(route1, "ACT001", "FGIN/TIPP/ERR_/0001/0000", null, "REQ_", "CP001",
                    "Start process CP001 when REQ_ on ERR_ Location"));
            repo.save(new Action(route1, "ACT002", null, "IPOINT", "REQ_", "CP002",
                    "Start process CP001 when REQ_ on any Location in IPOINT LocationGroup"));
            repo.save(new Action(route1, "ACT003", null, "FGINSORT", "REQ_", "CP002",
                    "Start process CP001 when REQ_ on any Location in FGINSORT LocationGroup"));

            repo.save(new Action(routeNO, "ACT004", null, "ZILE", "REQ_", "CP001",
                    "Start process CP001 when REQ_ on top-level LocationGroup and no defined route"));
            repo.save(new Action(routeDEF, "ACT005", null, "ZILE", "REQ_", "CP001",
                    "Start process CP001 when REQ_ on top-level LocationGroup and any other route"));
        }
    };
}

From source file:org.springframework.cloud.cloudfoundry.sample.DemoApplication.java

@Bean
CommandLineRunner consume(final LoadBalancerClient loadBalancerClient,
        final CloudFoundryDiscoveryClient discoveryClient, final HiServiceClient hiServiceClient,
        final RestTemplate restTemplate) {

    return new CommandLineRunner() {
        @Override/*from   w  ww . j  av  a2 s .  c  om*/
        public void run(String... args) throws Exception {

            try {
                // this demonstrates using the CF/Ribbon-aware RestTemplate
                // interceptor
                log.info("=====================================");
                log.info("Hi: "
                        + restTemplate.getForEntity("http://hi-service/hi/{name}", String.class, "Josh"));
            } catch (Exception e) {
                log.warn("Failed to fetch hi-service", e);
            }

            // this demonstrates using the Spring Cloud Commons DiscoveryClient
            // abstraction
            log.info("=====================================");
            for (String svc : discoveryClient.getServices()) {
                log.info("service = " + svc);
                List<ServiceInstance> instances = discoveryClient.getInstances(svc);
                for (ServiceInstance si : instances) {
                    log.info("\t"
                            + ReflectionToStringBuilder.reflectionToString(si, ToStringStyle.MULTI_LINE_STYLE));
                }
            }

            log.info("=====================================");
            log.info("local: ");
            log.info("\t" + ReflectionToStringBuilder.reflectionToString(
                    discoveryClient.getLocalServiceInstance(), ToStringStyle.MULTI_LINE_STYLE));

            try {
                // this demonstrates using a CF/Ribbon-aware Feign client
                log.info("=====================================");
                log.info("Hi:" + hiServiceClient.hi("Josh"));
            } catch (Exception e) {
                log.warn("Failed to fetch hi-service", e);
            }

            // this demonstrates using the Spring Cloud Commons LoadBalancerClient
            log.info("=====================================");
            ServiceInstance choose = loadBalancerClient.choose("hi-service");
            if (choose != null) {
                log.info("chose: " + '(' + choose.getServiceId() + ") " + choose.getHost() + ':'
                        + choose.getPort());
            }
        }
    };
}