当前位置: 首页>>代码示例>>Java>>正文


Java CommandLineRunner类代码示例

本文整理汇总了Java中org.springframework.boot.CommandLineRunner的典型用法代码示例。如果您正苦于以下问题:Java CommandLineRunner类的具体用法?Java CommandLineRunner怎么用?Java CommandLineRunner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CommandLineRunner类属于org.springframework.boot包,在下文中一共展示了CommandLineRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:InitDatabase.java

示例2: setUp

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
/**
 * Pre-load some fake images
 *
 * @return Spring Boot {@link CommandLineRunner} automatically run after app context is loaded.
 */
@Bean
CommandLineRunner setUp() throws IOException {
	return (args) -> {
		FileSystemUtils.deleteRecursively(new File(UPLOAD_ROOT));

		Files.createDirectory(Paths.get(UPLOAD_ROOT));

		FileCopyUtils.copy("Test file",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-cover.jpg"));

		FileCopyUtils.copy("Test file2",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-2nd-edition-cover.jpg"));

		FileCopyUtils.copy("Test file3",
			new FileWriter(UPLOAD_ROOT + "/bazinga.png"));
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:25,代码来源:ImageService.java

示例3: runner

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
public CommandLineRunner runner(GitterProperties props, MongoProperties mongoProperties) {
    return args -> {
        context.registerBean(Mate.class, () -> new Mate("Lithium", "Alex", true));
        Mate mate = context.getBean(Mate.class);
        System.out.println("Mate from context: " + mate.nickname);
        System.out.println("Gitter Room: " + props.getRoom());

        Flux<Mate> people = Flux.just(
                new Mate("aliaksei-lithium", "Aliaksei"),
                new Mate("IRus", "Ruslan"),
                new Mate("bsiamionau", "Bahdan")
        );
        repository.deleteAll().thenMany(repository.save(people)).blockLast();
    };
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:17,代码来源:Spring5demoApplication.java

示例4: commandLineRunner

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
    return args -> {

        System.out.println("Let's inspect the beans provided by Spring Boot:\n");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }

        System.out.println("---");
    };
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:17,代码来源:CalendarApplication.java

示例5: setUp

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
/**
 * Pre-load some test images
 *
 * @return Spring Boot {@link CommandLineRunner} automatically
 *         run after app context is loaded.
 */
@Bean
CommandLineRunner setUp() throws IOException {
	return (args) -> {
		FileSystemUtils.deleteRecursively(new File(UPLOAD_ROOT));

		Files.createDirectory(Paths.get(UPLOAD_ROOT));

		FileCopyUtils.copy("Test file",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-cover.jpg"));

		FileCopyUtils.copy("Test file2",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-2nd-edition-cover.jpg"));

		FileCopyUtils.copy("Test file3",
			new FileWriter(UPLOAD_ROOT + "/bazinga.png"));
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:26,代码来源:ImageService.java

示例6: init

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "phil"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:20,代码来源:InitDatabase.java

示例7: initializeUsers

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
CommandLineRunner initializeUsers(MongoOperations operations) {
	return args -> {
		operations.dropCollection(User.class);

		operations.insert(
			new User(
				null,
				"greg", "turnquist",
				new String[]{"ROLE_USER", "ROLE_ADMIN"}));
		operations.insert(
			new User(
				null,
				"phil", "webb",
				new String[]{"ROLE_USER"}));

		operations.findAll(User.class).forEach(user -> {
			System.out.println("Loaded " + user);
		});
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:22,代码来源:InitUsers.java

示例8: init

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:InitDatabase.java

示例9: demo

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
public CommandLineRunner demo(NoteRepository repository) {
	return (args) -> {
		// save a couple of notes
		repository.save(new NoteEntity("Spring Boot", "Need to implement REST Services"));
		repository.save(new NoteEntity("Learn Maven", "Learn the concept of Dependency Mangement"));
		repository.save(new NoteEntity("ABC", "Bla Bla Bla.."));

		// fetch all notes
		log.info("Customers found with findAll():");
		log.info("-------------------------------");
		for (NoteEntity notes : repository.findAll()) {
			log.info(notes.toString());
		}
	};
}
 
开发者ID:adityajadhav,项目名称:spring-boot-rest-example,代码行数:17,代码来源:Application.java

示例10: demo

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
public CommandLineRunner demo(NoteRepository repository) {
	return (args) -> {

		// save a couple of notes
		repository.save(new NoteEntity("Spring Boot", "Setup spring boot application"));
		repository.save(new NoteEntity("Maven Multi Module", "build a multi module maven project"));
		repository.save(new NoteEntity("Learn JPA", "Go though basic concepts of JPA"));

		// fetch all notes
		log.info("Notes found with findAll():");
		log.info("-------------------------------");
		for (NoteEntity notes : repository.findAll()) {
			log.info(notes.toString());
		}
	};
}
 
开发者ID:adityajadhav,项目名称:spring-boot-rest-example,代码行数:18,代码来源:Application.java

示例11: commandLineRunner

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> {

            String[] beanNames = ctx.getBeanDefinitionNames();

            System.out.println("********************************************");
            // TODO: FIXME: Logger level not working
            logger.debug("**************************************************");
            System.out.println("Listing the "+beanNames.length+" beans loaded by Spring Boot:");
//            logger.debug("Listing the {} beans loaded by Spring Boot:", beanNames.length);

            Arrays.stream(beanNames)
                    .sorted().forEach(System.out::println);

            logger.debug("*** the End **************************************\n\n");
            System.out.println("*** the End ********************************\n\n");
        };

    }
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:21,代码来源:CalendarApplication.java

示例12: init

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
CommandLineRunner init(
		AccountService accountService
) {
	return (evt) -> Arrays.asList(
			"user,admin,john,robert,ana".split(",")).forEach(
					username -> {
						Account acct = new Account();
						acct.setUsername(username);
						if ( username.equals("user")) acct.setPassword("password");
						else acct.setPassword(passwordEncoder().encode("password"));
						acct.setFirstName(username);
						acct.setLastName("LastName");
						acct.grantAuthority("ROLE_USER");
						if ( username.equals("admin") )
							acct.grantAuthority("ROLE_ADMIN");
						try {
							accountService.register(acct);
						} catch (AccountException e) {
							e.printStackTrace();
						}
					}
	);
}
 
开发者ID:tinmegali,项目名称:Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token,代码行数:25,代码来源:DemoOauth2Application.java

示例13: demo

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
public CommandLineRunner demo(AddressRepository repository) {
    return (args) -> {
        repository.save(new Address("DE", "Solingen", "42697", "Hochstraße", "11"));
        repository.save(new Address("DE", "Berlin", "10785", "Kemperplatz", "1"));
        repository.save(new Address("DE", "Dortmund", "44137", "Hoher Wall", "15"));
        repository.save(new Address("DE", "Düsseldorf", "40591", "Kölner Landstraße", "11"));
        repository.save(new Address("DE", "Frankfurt", "60486", "Kreuznacher Straße", "30"));
        repository.save(new Address("DE", "Hamburg", "22767", "Große Elbstraße", "14"));
        repository.save(new Address("DE", "Karlsruhe", "76135", "Gartenstraße", "69a"));
        repository.save(new Address("DE", "München", "80687", "Elsenheimerstraße", "55a"));
        repository.save(new Address("DE", "Münster", "48167", "Wolbecker Windmühle", "29j"));
        repository.save(new Address("DE", "Nürnberg", "90403", "Josephsplatz", "8"));
        repository.save(new Address("DE", "Stuttgart", "70563", "Curiesstraße", "2"));

        log.info("### Address count:" + repository.count());

    };
}
 
开发者ID:MrBW,项目名称:resilient-transport-service,代码行数:20,代码来源:AddressServiceApplication.java

示例14: lineRunner

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
CommandLineRunner lineRunner(QuestionRestRepository questionRestRepository) {
	return (args) -> {
		Question q = new Question();
		q.setContent("1+2");
		Answer a1 = new Answer();
		a1.setContent("2");
		Answer a2 = new Answer();
		a2.setContent("3");
		a2.setCorrect(true);
		Answer a3 = new Answer();
		a3.setContent("4");

		q.getAnswers().add(a1);
		q.getAnswers().add(a2);
		q.getAnswers().add(a3);

		questionRestRepository.save(q);
	};
}
 
开发者ID:FreeFly19,项目名称:athena-backend,代码行数:21,代码来源:AthenaBackendApplication.java

示例15: run

import org.springframework.boot.CommandLineRunner; //导入依赖的package包/类
@Bean
public CommandLineRunner run() {
    return args -> {
        logger.info("Ajout d'un nouveau document: {} / {} [{}]", newDocumentPath, newDocumentName, newDocumentLocation);
        final Path location = Paths.get(newDocumentLocation);
        logger.debug("Le fichier {} {}", location, Files.exists(location) ? "existe" : "n'existe pas");
        final AlfredService alfredService = alfredFactory.createAlfredServiceBuilder()
                .url(alfredUrl)
                .username(alfredUsername)
                .password(alfredPassword);

        final Supplier<NodeReference> createDocumentFromProperties = () -> createDocument(alfredService);

        final NodeReference nodeReference = alfredService
                .documentByNodeReference(nodeReferenceAddContent.orElseGet(createDocumentFromProperties))
                .content(location)
                .getNodeReference();
        logger.info("Le document {} a été poussé dans Alfresco. Il s'agit du noeud {}",
                newDocumentName,
                nodeReference.getNodeReference());
    };
}
 
开发者ID:avdyk,项目名称:be.liege.cti.ged,代码行数:23,代码来源:InsertNewImageExampleApp.java


注:本文中的org.springframework.boot.CommandLineRunner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。