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

Create Spring Boot Project

Reference

  • 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, @GetMapping etc
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
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
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

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