[英]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.