Spring Shell - 用法和执行

Spring Shell - usage and execution

我想将 Spring Shell 集成到 spring 启动应用程序中。我可以执行官方 git-repo. But when migrating the example code to my own project that is very very similar to 的示例,我的个人 shell 未显示或无法使用。相反,显示的默认 Spring Shell 启动画面可用:

<SpringShell ASCII-Art>
1.1.0.RELEASE

Welcome to Spring Shell. For assistance press or type "hint" then hit ENTER
spring-shell>

编译没有错误,但未使用标记为 类 的单个示例 @component。所有注释均已正确设置。外面有一个标准的装载机。我没有在 IDE.

中执行代码

尽管 documentation(第 3.5 章)告诉我,据我所知组件是自动收集的。

所以我的问题或多或少是如何设置使用比 这个:

public class Main {
    public static void main(String[] args) throws Exception {
        Bootstrap.main(args);
    }
}

并打败默认的启动画面!

文档中的评论有点误导(我会更改它)。 要获取您的组件,它们需要位于类路径中,并且您需要以某种方式扫描它们。

例如,请参阅 Spring XD project 中如何扫描 org.springframework.xd.shell 包。您需要为自己的包做类似的事情。

解决方案:

ebottard 的回答让我想在 resources\META-INF\spring\.. 下创建一个 "spring-shell-plugin.xml"。虽然已经在外部设置了组件扫描,但这似乎是必要的。以下代码显示了如何在实施了 CommandLineRunner 的 Spring 启动应用程序中启动它。这应该可以解决启动问题。

@Component
public class CLIBean implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.run();
    }

}