|
| 1 | += Spring Framework Core |
| 2 | +:figures: 11-development/02-spring/01-core |
| 3 | + |
| 4 | +== Generate a Spring Boot Application Using CLI |
| 5 | +Spring Boot is a framework that simplifies the development of Spring applications by providing a set of conventions and defaults. It allows developers to create stand-alone, production-grade applications with minimal configuration. |
| 6 | +You can generate a Spring Boot application using the Spring CLI by running the following command: |
| 7 | +[source, bash] |
| 8 | +---- |
| 9 | +spring init --dependencies=web,data-jpa,h2,devtools myapp |
| 10 | +---- |
| 11 | +== Generate a Spring Boot Application Using Curl |
| 12 | +[source, bash] |
| 13 | +---- |
| 14 | +curl https://start.spring.io/starter.zip -d groupId=com.polarbookshop -d artifactId=edge-service -d name=edge-service -d packageName=com.polarbookshop.edgeservice -d dependencies=web,data-jpa,h2,devtools -d javaVersion=17 -d bootVersion=3.3.0 -d type=maven-project -o edge-service.zip |
| 15 | +---- |
| 16 | +change type=maven-project to type=gradle-project if you want to generate a Gradle project. |
| 17 | +== Generate a Spring Boot Application Using JBang |
| 18 | +[source, bash] |
| 19 | +---- |
| 20 | +jbang init --name=myapp --dependencies=web,data-jpa,h2,devtools |
| 21 | +cd myapp |
| 22 | +jbang run |
| 23 | +---- |
| 24 | + |
| 25 | +== Generate a Spring Boot Application Using Maven |
| 26 | +[source, bash] |
| 27 | +---- |
| 28 | +mvn archetype:generate -DgroupId=com.example -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false |
| 29 | +cd myapp |
| 30 | +mvn spring-boot:run |
| 31 | +---- |
| 32 | +== Generate a Spring Boot Application Using Gradle |
| 33 | +[source, bash] |
| 34 | +---- |
| 35 | +gradle init --type java-application |
| 36 | +cd myapp |
| 37 | +./gradlew bootRun |
| 38 | +---- |
| 39 | +== Generate a Spring Boot Application Using IntelliJ IDEA |
| 40 | +1. Open IntelliJ IDEA and select "New Project". |
| 41 | +2. Choose "Spring Initializr" from the left panel. |
| 42 | +3. Fill in the project details such as Group, Artifact, Name, and Description. |
| 43 | +4. Select the dependencies you want to include, such as "Spring Web", "Spring Data JPA", "H2 Database", and "Spring Boot DevTools". |
| 44 | +5. Click "Finish" to create the project. |
| 45 | +6. IntelliJ IDEA will generate the project structure and download the necessary dependencies. |
| 46 | +7. You can then run the application by right-clicking on the main class (annotated with `@SpringBootApplication`) and selecting "Run". |
| 47 | + |
| 48 | +== Generate a Spring Boot Application Using Eclipse |
| 49 | +1. Open Eclipse and select "File" -> "New" -> "Other". |
| 50 | +2. Choose "Spring Starter Project" from the list. |
| 51 | +3. Fill in the project details such as Group, Artifact, Name, and Description. |
| 52 | +4. Select the dependencies you want to include, such as "Spring Web", "Spring Data JPA", "H2 Database", and "Spring Boot DevTools". |
| 53 | +5. Click "Finish" to create the project. |
| 54 | +6. Eclipse will generate the project structure and download the necessary dependencies. |
| 55 | +7. You can then run the application by right-clicking on the main class (annotated with `@SpringBootApplication`) and selecting "Run As" -> "Java Application". |
| 56 | + |
| 57 | +== Generate a Spring Boot Application Using Visual Studio Code |
| 58 | +1. Open Visual Studio Code and install the "Spring Boot Extension Pack" from the Extensions Marketplace. |
| 59 | +2. Press `Ctrl + Shift + P` to open the Command Palette. |
| 60 | +3. Type "Spring Initializr" and select "Spring Initializr: Generate a Maven Project" or "Spring Initializr: Generate a Gradle Project". |
| 61 | +4. Fill in the project details such as Group, Artifact, Name, and Description. |
| 62 | +5. Select the dependencies you want to include, such as "Spring Web", "Spring Data JPA", "H2 Database", and "Spring Boot DevTools". |
| 63 | +6. Click "Generate" to create the project. |
| 64 | +7. Visual Studio Code will generate the project structure and download the necessary dependencies. |
| 65 | +8. You can then run the application by opening the main class (annotated with `@SpringBootApplication`) and clicking the "Run" button in the top right corner or by using the terminal command `./mvnw spring-boot:run` or `./gradlew bootRun |
| 66 | +`. |
| 67 | + |
| 68 | +== Generate a Spring Boot Application Using Spring Initializr |
| 69 | +Spring Initializr is a web-based tool that allows you to generate a Spring Boot application with the desired dependencies and configurations. You can access it at [https://start.spring.io/](https://start.spring.io/). |
| 70 | + |
| 71 | +1. Open your web browser and go to [https://start.spring.io/](https://start.spring.io/). |
| 72 | +2. Fill in the project metadata such as Group, Artifact, Name, Description, and Package Name. |
| 73 | +3. Select the desired dependencies by searching for them or selecting from the list. For example, you can add "Spring Web", "Spring Data J PA", "H2 Database", and "Spring Boot DevTools". |
| 74 | +4. Choose the project type (Maven or Gradle) and the Java version you want to use. |
| 75 | +5. Click the "Generate" button to download a ZIP file containing the generated Spring Boot application. |
| 76 | +6. Extract the ZIP file to your desired location. |
| 77 | +7. Open the project in your preferred IDE (such as IntelliJ IDEA, Eclipse, or Visual Studio Code). |
| 78 | +8. You can then run the application by executing the main class (annotated with `@SpringBootApplication`) or using the terminal command `./mvnw spring-boot:run` or `./gradlew bootRun`. |
0 commit comments