zoukankan      html  css  js  c++  java
  • Ability to configure CLI as non-repl

    @SpringBootApplication
    public class NonInteractiveCliApp {
    
        /**
         * Configures non-interactive shell mode.
         */
        @Configuration
        public static class NonInteractiveConfig {
    
            @Autowired
            private ConfigurableEnvironment environment;
    
            @PostConstruct
            public void disableInteractiveShell() {
                InteractiveShellApplicationRunner.disable(environment);
            }
    
            @Bean
            @Lazy
            public NonInteractiveShellApplicationRunner nonInteractiveShellApplicationRunner(Parser parser, Shell shell) {
                return new NonInteractiveShellApplicationRunner(parser, shell);
            }
    
        }
    
        @Order(NonInteractiveShellApplicationRunner.PRECEDENCE)
        @RequiredArgsConstructor
        public static class NonInteractiveShellApplicationRunner implements ApplicationRunner {
    
            public static final int PRECEDENCE = InteractiveShellApplicationRunner.PRECEDENCE - 100;
    
            private final Parser parser;
            private final Shell shell;
    
            @Override
            public void run(ApplicationArguments args) throws Exception {
                String rawArgs = Arrays.stream(args.getSourceArgs()).collect(Collectors.joining(" "));
                Reader reader = new StringReader(rawArgs);
    
                // Use FileInputProvider to read the input arguments (it has little to do with files in fact).
                InputProvider inputProvider = new FileInputProvider(reader, parser);
                shell.run(inputProvider);
            }
        }
    
        public static void main(String[] args) {
            ConfigurableApplicationContext context = new SpringApplicationBuilder(NonInteractiveCliApp.class)
                    .web(WebApplicationType.NONE)
                    .run(args);
        }
    }

    原文链接: https://github.com/spring-projects/spring-shell/issues/241

  • 相关阅读:
    学习 JS 内容知识点与个人感悟【2】
    学习两天hml的感悟
    编程一星期感悟(上)
    java基础及练习题
    java基础程序代码及Scanner和Random
    java中Random和Scanner及其循环语句
    java语言及数据类型
    SQL含义+单行函数
    DTL+数据字典+序列、索引、视图
    sql plus及SQL语句
  • 原文地址:https://www.cnblogs.com/sanshuiqing/p/14713140.html
Copyright © 2011-2022 走看看