AndreaNobili
AndreaNobili

Reputation: 43047

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).

I always created Spring project from Eclipse, now I have to do it from IntelliJ (the comunity edition).

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. Why?

How can I create a simple Spring command line application in IntelliJ?

Upvotes: 2

Views: 1693

Answers (3)

brunocrt
brunocrt

Reputation: 780

1) Add the Plugin "Maven Archetype Catalogs" to 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.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

Upvotes: 2

Meo
Meo

Reputation: 12501

Create a Maven project, add spring-context dependency, create @Configuration class and run it:

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/

Upvotes: 0

Aleksandr Podkutin
Aleksandr Podkutin

Reputation: 2580

You can use Maven archetypes from Spring official archetype catalog for Spring Boot applications.

Press "Add Archetype..." button when create maven project:

enter image description here

Or choose Spring project type, like this:

enter image description here

Upvotes: 0

Related Questions