Skip to content

Latest commit

 

History

History
168 lines (144 loc) · 7.71 KB

README.md

File metadata and controls

168 lines (144 loc) · 7.71 KB

Spring examples

Spring project Directory examples\ contains Spring code examples coming from various websites - mostly from the Spring project.

demo Example

This example has the following directory structure :

> tree /f /a . | findstr /v /b [A-Z]
|   build.bat
|   build.gradle
|   pom.xml
\---src
    +---main
    |   +---java
    |   |   \---com
    |   |       \---example
    |   |           \---demo
    |   |                   DemoApplication.java
    |   \---resources
    |           application.properties
    \---test
        \---java
            \---com
                \---example
                    \---demo
                            DemoApplicationTests.java

Command build.bat-verbose run starts the Spring Boot server – if not yet running – and executes two HTTP requests (using cURL) :

> build -verbose run
Search for user process with name "demo-service"
Execute request "hello" to Spring Boot server "demo-service"
Hello World!
Execute request "hello?name=John" to Spring Boot server "demo-service"
Hello John!buil

🔎 We can also launch the Spring Boot server before executing the above HTTP requests :

> start "demo-service" mvn spring-boot:run

As a result the server process "demo-service" is started in a separate window session:

[...]
[INFO] Attaching agents: []
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.3.3)
[...]

Command buildstop terminates the server process :

> build -verbose stop
Search for user process with name "demo-service"
Stop server process "demo-service"

gs-rest-service Example

This example has the following directory structure :

> tree /f /a . | findstr /v /b [A-Z]
|   build.bat
|   build.gradle
|   manifest.yml
|   pom.xml
|   settings.gradle
\---src
    +---main
    |   +---java
    |   |   \---com
    |   |       \---example
    |   |           \---restservice
    |   |                   Greeting.java
    |   |                   GreetingController.java
    |   |                   RestServiceApplication.java
    |   \---resources
    |           application.properties
    \---test
        \---java
            \---com
                \---example
                    \---restservice
                            GreetingControllerTests.java

Command buildrun starts the Spring Boot server – if not yet running – and executes two HTTP requests (using cURL) :

> build -verbose run
Search for server process with name "gs-rest-service"
Execute request to server "gs-rest-service"
{
    "id": 1,
    "content": "Hello, World!"
}

Execute request to server "gs-rest-service"
{
    "id": 2,
    "content": "Hello, John!"
}

Command buildstop terminates the server process :

> build -verbose stop
Search for user process with name "gs-rest-service"
Stop server process "gs-rest-service"

🔎 We can also launch the Spring Boot server before executing the above HTTP requests :

> start "gs-rest-service" mvn spring-boot:run

As a result the server process "gs-test-service" is started in a separate window session:

[...]
[INFO] Attaching agents: []
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.3.3)
[...]

mics/December 2024