You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Shell内置组件无法显示,调用run()返回null问题求助

Spring Shell组件运行无显示且返回null问题

调用Spring Shell内置的StringInput、PathInput、ConfirmationInput、SingleSelect和MultiSelect组件时,调用其继承自AbstractComponent的run()方法后,界面无任何显示,且返回结果为null。调试发现组件构造方法中调用getTerminal()始终返回DumbTerminal。

相关代码

命令组件类

package com.example.demo;

import org.springframework.shell.component.StringInput;
import org.springframework.shell.component.StringInput.StringInputContext;
import org.springframework.shell.standard.AbstractShellComponent;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

@ShellComponent
public class ComponentCommands extends AbstractShellComponent {

    @ShellMethod(key = "component string", value = "String input", group = "Components")
    public String stringInput(boolean mask) {
        StringInput component = new StringInput(getTerminal(), "Enter value", "myvalue");
        component.setResourceLoader(getResourceLoader());
        component.setTemplateExecutor(getTemplateExecutor());
        if (mask) {
            component.setMaskCharater('*');
        }
        StringInputContext context = component.run(StringInputContext.empty());
        return "Got value " + context.getResultValue();
    }
}

Spring Boot启动类

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }

}

尝试的替代方案及问题

手动构建Terminal替换getTerminal()后,界面会出现提示,但输入的文本会覆盖提示内容,且无法通过回车确认输入:

Terminal terminal = TerminalBuilder.builder()
        .system(false)
        .streams(System.in, System.out)
        .build();
StringInput component = new StringInput(terminal, "Enter value", "myvalue");

已尝试在实体终端(非IDE)中运行程序,问题依旧存在。


内容的提问来源于stack exchange,提问作者μ-the-ultimate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 11:35:13