![](/img/trans.png)
[英]how IntelliJ is able to resolve dependencies and run a spring boot (maven) application while from the command line, it is not possible?
[英]How to correctly create a simple command line Spring application in IntelliJ?
我必須啟動一個簡單的Spring項目(它是一個批處理文件,它對數據庫執行查詢,然后迭代獲取的記錄)。
我總是從Eclipse創建Spring項目,現在我必須從IntelliJ(社區版)開始。
我正在嘗試做文件 - >新建 - >項目 ,這里我選擇了Maven但我找不到與簡單的Spring命令行應用程序的結構相關的原型。 為什么?
如何在IntelliJ中創建一個簡單的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();
}
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.