簡體   English   中英

如何在IntelliJ中正確創建一個簡單的命令行Spring應用程序?

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

我必須啟動一個簡單的Spring項目(它是一個批處理文件,它對數據庫執行查詢,然后迭代獲取的記錄)。

我總是從Eclipse創建Spring項目,現在我必須從IntelliJ(社區版)開始。

我正在嘗試做文件 - >新建 - >項目 ,這里我選擇了Maven但我找不到與簡單的Spring命令行應用程序的結構相關的原型。 為什么?

如何在IntelliJ中創建一個簡單的Spring命令行應用程序?

您可以使用Spring官方原型目錄中的 Maven原型進行Spring Boot應用程序。

創建maven項目時按“添加原型...”按鈕:

在此輸入圖像描述

或者選擇Spring項目類型,如下所示:

在此輸入圖像描述

創建一個Maven項目,添加spring-context依賴項,創建@Configuration類並運行它:

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

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

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) 基於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

這將告訴intelij下載新的原型並使用Spring Boot CommandLinner創建一個基於此原型的新maven項目和示例源代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM