Quick start – First Spring Boot App in Eclipse

In eclipse start a new maven project – Sample entries I had provided

sb-app

Edit the pom.xml file and add the following dependency – Want to test a simple rest endpoint app

<dependencies>
 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-rest</artifactId>
  </dependency>
</dependencies>

Add the following plugin for Maven to run the project

    <build>
        <plugins>
            <plugin>
     
      <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Create a new package demo (in src/main/java)

Create a simple User POJO (User.java) in src/main/java/demo

package demo;

import org.springframework.stereotype.Component;

@Component
public class User {
  private String firstName;
  private String lastName;
  private int id;
  public String getFirstName() {
    return firstName;
  }
  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }
 public String getLastName() {
   return lastName;
 }
 public void setLastName(String lastName) {
   this.lastName = lastName;
 }
 public int getId() {
   return id;
 }
 public void setId(int id) {
   this.id = id;
 }
}

Add a Controller (UserController.java) in (src/main/java/demo) class with on end point

package demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
 @RequestMapping(value="/test")
 public User getUserInfo(){
  User user = new User();
  user.setFirstName("First");
  user.setLastName("Last");
  user.setId(10);
  return user;
 }
}

Create one simple Application.java in src/main/java/demo with a main method (a requirement for spring boot)

package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
 SpringApplication.run(Application.class, args);
 }
}

Your are done with setting up – Right click on Application.java, Run As->Java Application – Your first spring boot app will be up and running. Open a browser and access localhost:8080/test and you should be able to view the JSON response.