Spring Boot Java Template

repository·main·Indexed 43 days ago

https://github.com/team-dodn/spring-boot-java-template

A modular Spring Boot Java template designed for scalability and productivity. It features a structured module system including Core for domain services, Clients for external integration via Spring-Cloud-Open-Feign, Storage for MySql connectivity using Spring-Data-JPA, and Support for logging with Sentry and monitoring. The template includes predefined runtime profiles (local, dev, staging, live) and centralized dependency management via gradle.properties.

Tokens
1.1K
Snippets
3
Records
8
Agent score
56%

What's inside Spring Boot Java Template

  1. Understand the SpringBoot Java Template module structure

    main

    The project is organized into functional modules designed to scale with your service. The structure is divided into several main categories:

    • Core: Contains domain services.
      • core:core-api: The only executable module. It provides APIs and framework setup. It is structured with domains to maximize initial productivity.
      • core:core-enum: Contains enums used by core-api that need to be shared with external modules.
    • Clients: Handles integration with external systems.
      • clients:clients-example: Demonstrates HTTP communication using Spring-Cloud-Open-Feign.
    • Storage: Handles storage integration.
      • storage:db-core: Demonstrates MySql connectivity using Spring-Data-JPA.
    • Support: Provides cross-cutting concerns.
      • support:logging: Provides logging with distributed tracing and Sentry support.
      • support:monitoring: Provides service monitoring.
    • Tests: Provides testing utilities.
      • tests:api-docs: Facilitates writing spring-rest-docs.
  2. Configure IntelliJ IDEA to run Gradle tests

    main

    To ensure test code runs smoothly out of the box, configure IntelliJ IDEA to use its own runner for Gradle tests:

    1. Open Settings/Preferences.
    2. Navigate to Build, Execution, Deployment > Build Tools > Gradle.
    3. Set Run tests using to IntelliJ IDEA.
    Build, Execution, Deployment > Build Tools > Gradle > Run tests using > IntelliJ IDEA
  3. Configure Spring Boot runtime profiles

    main

    The template provides several predefined runtime profiles for different environments:

    • local: Configures an environment for offline development (disconnected from network).
    • local-dev: Configures the local machine to connect to the DEV environment.
    • dev: Used for deploying to Development environments.
    • staging: Used for deploying to Staging environments.
    • live: Used for deploying to Live (Production) environments.
  4. Configure the core database datasource

    main

    The db-core module uses HikariCP for connection pooling. You can configure the core datasource properties using the storage.datasource.core prefix in your application configuration (e.g., application.yml or application.properties). These properties are mapped directly to a HikariConfig object.

    storage:
      datasource:
        core:
          jdbc-url: jdbc:postgresql://localhost:5432/mydb
          username: user
          password: password
          maximum-pool-size: 10
  5. Configure JPA and Transaction Management in db-core

    main

    The CoreJpaConfig class provides the foundational Spring configuration for JPA and transaction management within the db-core module. It automatically enables transaction management and configures scanning for JPA entities and repositories within the io.dodn.springboot.storage.db.core package hierarchy.

    When using this module, ensure your entities and repositories are located within or under the io.dodn.springboot.storage.db.core package to be automatically detected by this configuration.

  6. Run specific test tasks and groups

    main

    The project defines several test tasks and groupings. You can run these via Gradle:

    • test: A collection of test tasks intended for CI (Continuous Integration) environments. Settings are managed in build.gradle.
    • unitTest: Fast-running tests with no dependencies that target single features.
    • contextTest: Integration tests that run within a SpringContext.
    • restDocsTest: Generates asciidoc documentation using spring-rest-docs.
    • developTest: Tests that should not be run in CI. This is a recommended tag for tests that are not yet stable or reliable.