Skip to content

Instantly share code, notes, and snippets.

@simonovAlexey
Last active April 4, 2018 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonovAlexey/51166e11fe80c84f20c19527dd722788 to your computer and use it in GitHub Desktop.
Save simonovAlexey/51166e11fe80c84f20c19527dd722788 to your computer and use it in GitHub Desktop.
Excample use a CommandLineRunner of Spring Boot
@Configuration
public class AppConfig {
// @return Spring Boot {@link CommandLineRunner} automatically
// run after app context is loaded.
@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("---");
};
}
//also supports:
// @Bean
// public CommandLineRunner commandLineRunner(TransactionServiceImpl transactionService) {
// return args -> {
// transactionService.init();
// LOGGER.info("done");
// };
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment