A custom Spring Boot starter that provides automatic method execution time logging using Aspect-Oriented Programming ( AOP).
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.
logging-starter- Custom Spring Boot starter with AOP logging functionalitysrc- Demo Spring Boot application with REST API
├── 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
- ✅ Automatic Method Timing - Logs execution time of all methods in Spring
@Servicecomponents - ✅ 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
- ✅ 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
cd logging-starter
mvn clean installcd src
mvn spring-boot:runcurl http://localhost:8080/api/pingInclude the dependency in your pom.xml:
<dependency>
<groupId>com.aop.logging_starter</groupId>
<artifactId>logging_starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>@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);
}
}# application.yml
app:
logging:
enabled: true # Enable/disable the logging aspect
server:
port: 8080
spring:
application:
name: demo-appWhen 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