A minimalist Spring Boot learning project designed for exploring Spring features, implementing POCs, and hands-on learning through feature development.
This project serves as a sandbox for experimenting with Spring Boot capabilities. The simple, clean structure allows you to focus on learning and implementing features without unnecessary boilerplate or complexity.
src/
βββ main/
β βββ java/no/mlz/springlab/
β β βββ SpringlabApplication.java # Main application entry point
β βββ resources/
β βββ application.yml # Spring configuration
β βββ logback-spring.xml # Logging configuration
βββ test/
βββ java/no/mlz/springlab/
βββ SpringlabApplicationTests.java
- Spring Boot Auto-Configuration: Sensible defaults for rapid development
- H2 In-Memory Database: Pre-configured for quick database testing and learning
- Web console available at
http://localhost:8080/h2-console - Auto-creates schema on startup, drops on shutdown
- Perfect for POCs and learning JPA/Hibernate
- Web console available at
- Comprehensive Logging:
- Console output with color-coded log levels
- Rolling file appenders (main, debug, error logs)
- Async logging for non-blocking file writes
- Configurable log levels per package
The project includes three separate log files:
spring-lab.log: General application logsspring-lab-debug.log: Detailed debug information with line numbersspring-lab-error.log: Error-only logs
Log rotation is configured with:
- Max file size: 10MB
- Max history: 30 days
- Total size cap: 1-2GB
- Java 11+ (verify with
java -version) - Maven 3.6+ (verify with
mvn -version)
# Build the project
mvn clean install
# Run the application
mvn spring-boot:runmvn testApplication settings can be modified in src/main/resources/application.yml:
spring:
application:
name: spring-lab
datasource:
url: jdbc:h2:mem:springlab_db
driverClassName: org.h2.Driver
username: sa
password:
h2:
console:
enabled: true
path: /h2-console
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: create-drop # Options: create-drop, create, update, validate, none
show-sql: false
properties:
hibernate:
format_sql: true
use_sql_comments: true
logging:
level:
root: INFO
no.mlz.springlab: DEBUGThe H2 database console is available at http://localhost:8080/h2-console when the application is running.
Connection Details:
- JDBC URL:
jdbc:h2:mem:springlab_db - Username:
sa - Password: (leave blank)
The in-memory database is created on startup and destroyed on shutdown, making it perfect for testing and learning.
Here are some suggested areas to explore:
- Create a
controllerpackage and implement@RestControllerendpoints - Practice
@GetMapping,@PostMapping, request validation
- Add Spring Data JPA dependency
- Create entity classes and repositories
- Experiment with query methods
- Create a
servicepackage with business logic - Practice
@Serviceand@Transactionalannotations
- Use
@Configurationand@Beanfor custom configurations - Explore profiles (
application-dev.yml,application-prod.yml)
- Implement
@RestControllerAdvicefor global exception handling - Create custom exceptions
no.mlz.springlab/
βββ controller/ # REST endpoints
βββ service/ # Business logic
βββ repository/ # Data access
βββ entity/ # JPA entities
βββ dto/ # Data transfer objects
βββ exception/ # Custom exceptions
βββ config/ # Configuration classes
βββ util/ # Utility classes
Current dependencies (from pom.xml):
- Spring Boot Starter Web
- Spring Boot Starter Data JPA
- H2 Database (runtime)
- Spring Boot Starter Test
To add new dependencies, edit pom.xml and run mvn clean install.
When implementing features, use logging effectively:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class MyService {
private static final Logger logger = LoggerFactory.getLogger(MyService.class);
public void doSomething() {
logger.debug("Entering doSomething");
logger.info("Processing request");
logger.warn("This is a warning");
logger.error("An error occurred", exception);
}
}Application logs are available in the logs/ directory. Monitor them during development:
# Watch main log in real-time
tail -f logs/spring-lab.log
# View debug logs
tail -f logs/spring-lab-debug.log
# View error logs
tail -f logs/spring-lab-error.logmvn clean package
java -jar target/springlab-0.0.1-SNAPSHOT.jarmvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=dev"- Start Small: Implement one feature at a time
- Use Logging: Leverage the configured logging to understand flow
- Write Tests: Test-driven development helps solidify understanding
- Check Logs: Always check the debug and error logs for insights
- Experiment: Use POCs to try new patterns and approaches
This is a personal learning project.