add springboot quick guide

main
Yik Teng Hie 5 years ago
parent be5175b469
commit ed12924535

@ -0,0 +1,71 @@
# Create Spring Boot Project
* Browse [Spring Initialzr](https://start.spring.io/)
* Option to select
* Gradle
* Java 8
* Dependencies
* Lombok
* Spring Web / REST Repositories
* Download the generated project
* Open with `IntelliJ IDEA`
# Create REST endpoint
* Create a java class
* Annotation with `@RESTController`, `@GetMapping` etc
```java
package com.razer.starter.api.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
public class HomeController {
@GetMapping("/home1")
@ResponseBody
public String Home(){
// log instaciate from @Slf4j annotation
log.info("home...");
return "Welcome Home";
}
}
```
* Run the project
```sh
./gradlew bootRun
```
* Browse [localhost](http://localhost:8080/home1) to reach the endpoint
```text
home...
```
## Create IntelliJ Debug Configuration
* `Run `> `Edit Configuration...`
* Add 'bootRun' Task. Click 'Ok'
* Now `Run...` or `Debug...` accordingly
* Alternatively, goto `main` and right click on side bar to run / debug
```java
public class StarterApplication {
private static final Logger log = LoggerFactory.getLogger(StarterApplication.class);
public static void main(String[] args) {
SpringApplication.run(StarterApplication.class, args);
}
}
```
Loading…
Cancel
Save