Skip to content

Latest commit

 

History

History
82 lines (66 loc) · 2.73 KB

03-2-B-Backend-Setup.adoc

File metadata and controls

82 lines (66 loc) · 2.73 KB

Setting up a Spring/Spring Boot backend app with Gradle

  1. Install the Spring Boot CLI

  2. Create a new repository under your account on GitHub for an example application that we are going to develop throughout the semester. Name the repository eventregistration. See more on the specification of the application functionality later.
    Create new eventregistration repo

  3. Clone it somewhere on your disk. We assume you cloned it to ~/git/eventregistration.

  4. Navigate to that folder in the terminal: cd ~/git/eventregistration.

  5. Create a project for the backend application using Spring Boot CLI in this repository.

    spring init \
     --build=gradle \
     --java-version=1.8 \
     --package=ca.mcgill.ecse321.eventregistration \
     --name=EventRegistration \
     --dependencies=web,data-jpa,postgresql \
     EventRegistration-Backend
    Note
    Backslashes in this snippet indicate linebreaks in this one liner command typed in the terminal. You can select and copy-paste this snippet as-is.
  6. Navigate to the EventRegistration-Backend folder

  7. For future use, locate the application.properties file in the src/ folder and add the following content:

    server.port=${PORT:8080}
    
    spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
    spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
    Note
    It may be the case that the PostgreSQLDialect needs to be changed for certain database instances (e.g., to PostgreSQL9Dialect).
  8. Locate the Java file containing the main application class (EventRegistrationApplication.java) and add the following content

    package ca.mcgill.ecse321.eventregistration;
    
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.SpringApplication;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @RestController
    @SpringBootApplication
    public class EventRegistrationApplication {
    
      public static void main(String[] args) {
        SpringApplication.run(EventRegistrationApplication.class, args);
      }
    
      @RequestMapping("/")
      public String greeting(){
        return "Hello world!";
      }
    
    }
  9. Verify that it builds with gradle build -xtest.

  10. Commit and push the files of the new Spring project.

    git add .
    git status #verify the files that are staged for commit
    git commit -m "Initial commit of the backend application"
    git push