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

  • 相关阅读:
    ASP实现禁止从外部提交数据
    随机提取N条记录[多种数据库方法]
    创建一个带滚动条的div
    将IP最后一位替换为星号
    用PHP5写的smtp类,支持身份验证、附件、抄送、暗送
    1004
    1021
    ProcessMonitor
    悲观锁和事务处理并发冲突
    spring.net入门
  • 原文地址:https://www.cnblogs.com/sanshuiqing/p/14713140.html
Copyright © 2011-2022 走看看