$npx -y skills add github/awesome-copilot --skill create-spring-boot-java-projectCreate Spring Boot Java Project Skeleton
| 1 | # Create Spring Boot Java project prompt |
| 2 | |
| 3 | - Please make sure you have the following software installed on your system: |
| 4 | |
| 5 | - Java 21 |
| 6 | - Docker |
| 7 | - Docker Compose |
| 8 | |
| 9 | - If you need to custom the project name, please change the `artifactId` and the `packageName` in [download-spring-boot-project-template](#download-spring-boot-project-template) |
| 10 | |
| 11 | - If you need to update the Spring Boot version, please change the `bootVersion` in [download-spring-boot-project-template](#download-spring-boot-project-template) |
| 12 | |
| 13 | ## Check Java version |
| 14 | |
| 15 | - Run following command in terminal and check the version of Java |
| 16 | |
| 17 | ```shell |
| 18 | java -version |
| 19 | ``` |
| 20 | |
| 21 | ## Download Spring Boot project template |
| 22 | |
| 23 | - Run following command in terminal to download a Spring Boot project template |
| 24 | |
| 25 | ```shell |
| 26 | curl https://start.spring.io/starter.zip \ |
| 27 | -d artifactId=${input:projectName:demo-java} \ |
| 28 | -d bootVersion=3.4.5 \ |
| 29 | -d dependencies=lombok,configuration-processor,web,data-jpa,postgresql,data-redis,data-mongodb,validation,cache,testcontainers \ |
| 30 | -d javaVersion=21 \ |
| 31 | -d packageName=com.example \ |
| 32 | -d packaging=jar \ |
| 33 | -d type=maven-project \ |
| 34 | -o starter.zip |
| 35 | ``` |
| 36 | |
| 37 | ## Unzip the downloaded file |
| 38 | |
| 39 | - Run following command in terminal to unzip the downloaded file |
| 40 | |
| 41 | ```shell |
| 42 | unzip starter.zip -d ./${input:projectName:demo-java} |
| 43 | ``` |
| 44 | |
| 45 | ## Remove the downloaded zip file |
| 46 | |
| 47 | - Run following command in terminal to delete the downloaded zip file |
| 48 | |
| 49 | ```shell |
| 50 | rm -f starter.zip |
| 51 | ``` |
| 52 | |
| 53 | ## Change directory to the project root |
| 54 | |
| 55 | - Run following command in terminal to change directory to the project root |
| 56 | |
| 57 | ```shell |
| 58 | cd ${input:projectName:demo-java} |
| 59 | ``` |
| 60 | |
| 61 | ## Add additional dependencies |
| 62 | |
| 63 | - Insert `springdoc-openapi-starter-webmvc-ui` and `archunit-junit5` dependency into `pom.xml` file |
| 64 | |
| 65 | ```xml |
| 66 | <dependency> |
| 67 | <groupId>org.springdoc</groupId> |
| 68 | <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> |
| 69 | <version>2.8.6</version> |
| 70 | </dependency> |
| 71 | <dependency> |
| 72 | <groupId>com.tngtech.archunit</groupId> |
| 73 | <artifactId>archunit-junit5</artifactId> |
| 74 | <version>1.2.1</version> |
| 75 | <scope>test</scope> |
| 76 | </dependency> |
| 77 | ``` |
| 78 | |
| 79 | ## Add SpringDoc, Redis, JPA and MongoDB configurations |
| 80 | |
| 81 | - Insert SpringDoc configurations into `application.properties` file |
| 82 | |
| 83 | ```properties |
| 84 | # SpringDoc configurations |
| 85 | springdoc.swagger-ui.doc-expansion=none |
| 86 | springdoc.swagger-ui.operations-sorter=alpha |
| 87 | springdoc.swagger-ui.tags-sorter=alpha |
| 88 | ``` |
| 89 | |
| 90 | - Insert Redis configurations into `application.properties` file |
| 91 | |
| 92 | ```properties |
| 93 | # Redis configurations |
| 94 | spring.data.redis.host=localhost |
| 95 | spring.data.redis.port=6379 |
| 96 | spring.data.redis.password=rootroot |
| 97 | ``` |
| 98 | |
| 99 | - Insert JPA configurations into `application.properties` file |
| 100 | |
| 101 | ```properties |
| 102 | # JPA configurations |
| 103 | spring.datasource.driver-class-name=org.postgresql.Driver |
| 104 | spring.datasource.url=jdbc:postgresql://localhost:5432/postgres |
| 105 | spring.datasource.username=postgres |
| 106 | spring.datasource.password=rootroot |
| 107 | spring.jpa.hibernate.ddl-auto=update |
| 108 | spring.jpa.show-sql=true |
| 109 | spring.jpa.properties.hibernate.format_sql=true |
| 110 | ``` |
| 111 | |
| 112 | - Insert MongoDB configurations into `application.properties` file |
| 113 | |
| 114 | ```properties |
| 115 | # MongoDB configurations |
| 116 | spring.data.mongodb.host=localhost |
| 117 | spring.data.mongodb.port=27017 |
| 118 | spring.data.mongodb.authentication-database=admin |
| 119 | spring.data.mongodb.username=root |
| 120 | spring.data.mongodb.password=rootroot |
| 121 | spring.data.mongodb.database=test |
| 122 | ``` |
| 123 | |
| 124 | ## Add `docker-compose.yaml` with Redis, PostgreSQL and MongoDB services |
| 125 | |
| 126 | - Create `docker-compose.yaml` at project root and add following services: `redis:6`, `postgresql:17` and `mongo:8`. |
| 127 | |
| 128 | - redis service should have |
| 129 | - password `rootroot` |
| 130 | - mapping port 6379 to 6379 |
| 131 | - mounting volume `./redis_data` to `/data` |
| 132 | - postgresql service should have |
| 133 | - password `rootroot` |
| 134 | - mapping port 5432 to 5432 |
| 135 | - mounting volume `./postgres_data` to `/var/lib/postgresql/data` |
| 136 | - mongo service should have |
| 137 | - initdb root username `root` |
| 138 | - initdb root password `rootroot` |
| 139 | - mapping port 27017 to 27017 |
| 140 | - mounting volume `./mongo_data` to `/data/db` |
| 141 | |
| 142 | ## Add `.gitignore` file |
| 143 | |
| 144 | - Insert `redis_data`, `postgres_data` and `mongo_data` directories in `.gitignore` file |
| 145 | |
| 146 | ## Run Maven test command |
| 147 | |
| 148 | - Run maven clean test command to check if the project is working |
| 149 | |
| 150 | ```shell |
| 151 | ./mvnw clean test |
| 152 | ``` |
| 153 | |
| 154 | ## Run Maven run command (Optional) |
| 155 | |
| 156 | - (Optional) `docker-compose up -d` to start the services, `./mvnw spring-boot:run` to run the Spring Boot project, `docker-compose rm -sf` to stop the services. |
| 157 | |
| 158 | ## Let's do this step by step |