|
|
|
|
# Create Spring Boot Project
|
|
|
|
|
|
|
|
|
|
[Reference](https://spring.io/projects/spring-boot)
|
|
|
|
|
|
|
|
|
|
* 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")
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
[Build Application Guide](https://spring.io/guides/gs/spring-boot/)
|
|
|
|
|
|
|
|
|
|
## Run Application
|
|
|
|
|
|
|
|
|
|
* From CLI
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
// spring.profiles.active to load .properties file according to profile setting
|
|
|
|
|
// below load [resources/application-prod.properties]
|
|
|
|
|
$ java -Dspring.profiles.active=prod -jar app.jar
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* dd
|