Skip to content

ForwardMoth/spring-boot-starter-demo-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot AOP Logging Starter

A custom Spring Boot starter that provides automatic method execution time logging using Aspect-Oriented Programming ( AOP).

🚀 Overview

This project demonstrates how to create a custom Spring Boot starter that automatically logs method execution times for all Spring @Service components. The solution uses AOP to provide non-invasive performance monitoring without modifying existing business logic.

Components

  • logging-starter - Custom Spring Boot starter with AOP logging functionality
  • src - Demo Spring Boot application with REST API

📁 Project Structure

├── logging-starter/ # Custom Spring Boot Starter
│ ├── src/main/java/
│ │     └── com/aop/logging_starter/
│ │     ├── aspect/
│ │     │   └── LoggingAspect.java
│ │     ├── config/
│ │     │   └── LoggingConfiguration.java
│ │     └── properties/
│ │         └── LoggingProperties.java
│ ├── src/main/resources/META-INF/spring/
│ │     └── org.springframework.boot.autoconfigure.AutoConfiguration.imports
│ └── pom.xml
│
└── src/ # Demo Spring Boot Application
├── src/main/java/com/aop/demo_app/
│   ├── controller/
│   │     └── PingController.java
│   ├── dto/
│   │     └── CommentResponse.java
│   ├── service/
│   │     ├── PingService.java
│   │     └── impl/
│   │         └── PingServiceImpl.java
│   └── DemoAppApplication.java
├── src/main/resources/
│   └── application.yml
└── pom.xml

✨ Features

Logging Starter

  • Automatic Method Timing - Logs execution time of all methods in Spring @Service components
  • AOP-Powered - Non-invasive method interception using Spring AOP
  • Configurable - Enable/disable via application properties
  • Production Ready - Proper error handling and logging
  • Spring Boot 3.x Compatible - Uses modern auto-configuration patterns

Demo Application

  • Simple REST API - Clean endpoint to demonstrate functionality
  • Modern Stack - Spring Boot 3.5.7 + Java 17 + Lombok
  • Ready to Run - Fully functional Spring Boot application

🛠 Installation

1. Build the Custom Starter

cd logging-starter
mvn clean install

2. Run the Demo Application

cd src
mvn spring-boot:run

3. Test the API

curl http://localhost:8080/api/ping

📖 Usage

Adding the Starter to Your Project

Include the dependency in your pom.xml:

<dependency>
    <groupId>com.aop.logging_starter</groupId>
    <artifactId>logging_starter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

Example Service (Automatically Logged)

@Service
public class UserService {

    public User findUser(Long id) {
        // Method execution time will be automatically logged
        return userRepository.findById(id);
    }

    public void processOrder(Order order) {
        // This method will also be automatically timed
        orderProcessor.process(order);
    }

}

⚙ Configuration

Application Properties

# application.yml
app:
  logging:
    enabled: true  # Enable/disable the logging aspect

server:
  port: 8080

spring:
  application:
    name: demo-app

📊 Example Output

When the application runs and you call the API, you'll see log output like:

2025-11-19T12:43:32.988+03:00  INFO 12192 --- [demo-app] [nio-8080-exec-1] c.a.d.service.impl.PingServiceImpl       : Method 'ping' executed in 1 ms

About

Custom Demo Spring Boot Starter for Method Execution Time Logging

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages