0

我想将 Spring Shell 集成到 Spring Boot 应用程序中。我能够执行官方git-repo中的示例。但是,当将示例代码迁移到与此代码非常相似的我自己的项目时,我的个人 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 中执行代码。

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

所以我的问题或多或少是如何设置比这更好的用法:

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

并击败默认的飞溅!

4

2 回答 2

1

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

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

于 2015-06-07T09:26:39.297 回答
0

解决方案:

ebottard 的回答让我想到了在resources\META-INF\spring\... 尽管组件扫描已在外部设置,但这似乎是必要的。以下代码显示了如何在实现的 Spring Boot 应用程序中启动它CommandLineRunner。这应该可以解决启动问题。

@Component
public class CLIBean implements CommandLineRunner {

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

}
于 2015-06-08T20:25:56.380 回答