Project Setup with Spring Initializr

🌿 Spring BootLesson 2Beginner

Spring Initializr at start.spring.io is the official project bootstrapper. It generates a ready-to-run Maven or Gradle project with your chosen dependencies in seconds.

1 Project Structure
Shell — Standard Maven Project Layout
my-api/
  src/
    main/
      java/com/example/myapi/
        MyApiApplication.java    # Entry point
        controller/              # REST controllers
        service/                 # Business logic
        repository/              # Data access
        model/                   # Entity classes
        dto/                     # Data Transfer Objects
        config/                  # Configuration classes
        exception/               # Custom exceptions
      resources/
        application.properties   # Configuration
        application-dev.properties
        application-prod.properties
    test/
      java/com/example/myapi/   # Test classes
  pom.xml                        # Maven dependencies
2 pom.xml — Essential Dependencies
XML — pom.xml
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>3.3.0</version>
</parent>

<dependencies>
  <!-- Web MVC + Embedded Tomcat -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  <!-- Spring Data JPA + Hibernate -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>

  <!-- PostgreSQL Driver -->
  <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
  </dependency>

  <!-- Validation -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
  </dependency>

  <!-- Lombok (reduces boilerplate) -->
  <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
  </dependency>

  <!-- Testing -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>
3 application.properties
Properties — application.properties
# Server
server.port=8080
spring.application.name=my-api

# Database
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=secret
spring.datasource.driver-class-name=org.postgresql.Driver

# JPA / Hibernate
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true

# Custom property
app.version=1.0.0
app.name=My Spring Boot API
4 Code Challenge
Challenge: Use start.spring.io to generate a Spring Boot 3 project with Web, JPA, PostgreSQL, Validation, and Lombok. Import it into IntelliJ IDEA, run it, and confirm the embedded Tomcat starts on port 8080.