You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.8 KiB
1.8 KiB
Create Spring Boot Project
- Browse Spring Initialzr
- 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,@GetMappingetc
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
./gradlew bootRun
- Browse localhost to reach the endpoint
home...
Create IntelliJ Debug Configuration
Run>Edit Configuration...- Add
bootRunTask. ClickOK - Now
Run...orDebug...accordingly - Alternatively, goto
mainand right click on side bar to run / debug
public class StarterApplication {
private static final Logger log = LoggerFactory.getLogger(StarterApplication.class);
public static void main(String[] args) {
SpringApplication.run(StarterApplication.class, args);
}
}
Run Application
- From CLI
// 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