简体   繁体   English

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

[英]How to correctly create a simple command line Spring application in IntelliJ?

I have to start a simple Spring project (it is a batch file that perform a query on a database and then iterate on the obtained records). 我必须启动一个简单的Spring项目(它是一个批处理文件,它对数据库执行查询,然后迭代获取的记录)。

I always created Spring project from Eclipse, now I have to do it from IntelliJ (the comunity edition). 我总是从Eclipse创建Spring项目,现在我必须从IntelliJ(社区版)开始。

I am trying to do File --> New --> Project , here I select Maven but I can't find archetype related to the structure of a simple Spring command line application. 我正在尝试做文件 - >新建 - >项目 ,这里我选择了Maven但我找不到与简单的Spring命令行应用程序的结构相关的原型。 Why? 为什么?

How can I create a simple Spring command line application in IntelliJ? 如何在IntelliJ中创建一个简单的Spring命令行应用程序?

You can use Maven archetypes from Spring official archetype catalog for Spring Boot applications. 您可以使用Spring官方原型目录中的 Maven原型进行Spring Boot应用程序。

Press "Add Archetype..." button when create maven project: 创建maven项目时按“添加原型...”按钮:

在此输入图像描述

Or choose Spring project type, like this: 或者选择Spring项目类型,如下所示:

在此输入图像描述

Create a Maven project, add spring-context dependency, create @Configuration class and run it: 创建一个Maven项目,添加spring-context依赖项,创建@Configuration类并运行它:

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

Full tutorial: https://projects.spring.io/spring-framework/ 完整教程: https//projects.spring.io/spring-framework/

1) Add the Plugin "Maven Archetype Catalogs" to Intelij 1) 将插件 “Maven Archetype Catalogs”添加到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) Create a New Project on Intelij based on Spring Boot Sample Simple Archetype 2) 基于Spring Boot Sample Simple Archetype在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

This will tell the intelij to download the new archetype and create a new maven project based on this archetype with sample source code using Spring Boot CommandLinner 这将告诉intelij下载新的原型并使用Spring Boot CommandLinner创建一个基于此原型的新maven项目和示例源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IntelliJ 如何能够从命令行解决依赖关系并运行 spring 引导(maven)应用程序,这是不可能的? - how IntelliJ is able to resolve dependencies and run a spring boot (maven) application while from the command line, it is not possible? 如何在没有IntelliJ模板的情况下创建命令行应用程序? - How to create command-line app without IntelliJ template? IntelliJ 的问题 - 无法运行简单的 Spring 应用程序 - Problem with IntelliJ - Cannot run simple Spring Application 如何在 Intellij IDEA 13.1 中使用 Maven 结构创建 Spring MVC 应用程序? - How to create Spring MVC application with Maven structure in Intellij IDEA 13.1? 如何在 Intellij 中使用 bean 创建基本的 spring 应用程序 - How to create a basic spring application using beans in Intellij Vaadin应用程序可从命令行运行,但不能在IntelliJ中运行 - Vaadin application working from command line but not in IntelliJ JavaFX应用程序未从命令行运行/如何正确构建和导出? - JavaFX application not running from command line / how to build and export correctly? 找不到创建命令行启动器 Intellij - Create Command-line Launcher Intellij not found 如何将程序参数传递给 spring boot 命令行应用程序? - How to pass programs arguments to spring boot command line application? 如何通过命令行启动 spring-boot 应用程序? - How to start up spring-boot application via command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM