Java 如何在IntelliJ中正确创建简单的命令行Spring应用程序?

Java 如何在IntelliJ中正确创建简单的命令行Spring应用程序?,java,spring,maven,intellij-idea,ide,Java,Spring,Maven,Intellij Idea,Ide,我必须启动一个简单的Spring项目(它是一个批处理文件,在数据库上执行查询,然后对获得的记录进行迭代) 我总是从Eclipse创建Spring项目,现在我必须从IntelliJ(comunity版)来创建它 我正在尝试执行文件-->新建-->项目,这里我选择了Maven,但我找不到与简单Spring命令行应用程序结构相关的原型。为什么? 如何在IntelliJ中创建一个简单的Spring命令行应用程序?您可以在Spring引导应用程序中使用中的Maven原型 创建maven项目时按“添加原型…

我必须启动一个简单的Spring项目(它是一个批处理文件,在数据库上执行查询,然后对获得的记录进行迭代)

我总是从Eclipse创建Spring项目,现在我必须从IntelliJ(comunity版)来创建它

我正在尝试执行文件-->新建-->项目,这里我选择了Maven,但我找不到与简单Spring命令行应用程序结构相关的原型。为什么?


如何在IntelliJ中创建一个简单的Spring命令行应用程序?

您可以在Spring引导应用程序中使用中的Maven原型

创建maven项目时按“添加原型…”按钮:

或者选择Spring项目类型,如下所示:


创建一个Maven项目,添加依赖项,创建@Configuration类并运行它:

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
    MessagePrinter printer = context.getBean(MessagePrinter.class);
    printer.printMessage();
}
完整教程:

1)将插件“Maven原型目录”添加到Intelij

1.1) File -> Settings -> Plugins -> Browse repositories...

1.2) Search for "Maven archetype" and look for the "Maven Archetype Catalogs"

1.3) Click on Install button of that plugin. After finished click the restart intelij button
2) 基于Spring Boot示例简单原型在Intelij上创建一个新项目

2.1) File -> New -> Project

2.2) Check the option "Create from archetype" and click the Add Archetype button

2.3) Fill the window fields with the following information

    GroupId: org.springframework.boot
    ArtifactId: spring-boot-sample-simple-archetype
    Version: 1.0.2.RELEASE
    Repository: http://central.maven.org/maven2/

2.4) Click OK
这将告诉intelij下载新的原型并创建一个新的maven项目
基于此原型,使用Spring Boot CommandLinner的示例源代码尝试一下,在我看来,您正在添加一个“Spring Boot”archtype。我不需要Spring引导,只需要一个简单的Spring应用程序(它更像是一个批处理应用程序,而不是与web相关的应用程序)。为什么要添加此原型?@AndreaNobili这只是一个例子,您可以在原型目录中找到
spring boot示例批处理原型。
。是的,只有spring boot原型(如果我想构建一个简单的spring应用程序,我能做什么?@AndreaNobili我补充了我的答案。