SpringBoot - Building a RESTful Web Service
Building a RESTful Web Service
- Get from Version Control https://github.com/spring-guides/gs-rest-service.git
2. start server
C:\Users\Admin>d: D:\>cd D:\Git Resposity\gs-rest-service\complete D:\Git Resposity\gs-rest-service\complete>mvnw spring-boot:run
3. New command window.
C:\Users\Admin>curl http://localhost:8080/greeting {"id":1,"content":"Hello, World!"} C:\Users\Admin>
4. Build runnable Jar
C:\Users\Admin>d: D:\>cd D:\Git Resposity\gs-rest-service\complete D:\Git Resposity\gs-rest-service\complete>mvnw clean package Found "D:\Git Resposity\gs-rest-service\complete\.mvn\wrapper\maven-wrapper.jar"
...
MockHttpServletResponse:
Status = 200
Error message = null
Headers = [Content-Type:"application/json"]
Content type = application/json
Body = {"id":2,"content":"Hello, Spring Community!"}
Forwarded URL = null
Redirected URL = null
Cookies = []
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.981 s - in com.example.restservice.GreetingControllerTests
2021-07-07 07:51:49.483 INFO 41736 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ rest-service ---
[INFO] Building jar: D:\Git Resposity\gs-rest-service\complete\target\rest-service-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ rest-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.483 s
[INFO] Finished at: 2021-07-07T07:51:50+08:00
[INFO] ------------------------------------------------------------------------
D:\Git Resposity\gs-rest-service\complete>
5. close all opened cmd windows, service not accessable.
6. open new CMD window
C:\Users\Admin>d: D:\>cd D:\Git Resposity\gs-rest-service\complete D:\Git Resposity\gs-rest-service\complete>java -jar target/rest-service-0.0.1-SNAPSHOT.jar
7. test again and successfully