Spring Commander is a lightweight framework for implementing the Command-Query Separation (CQS) pattern in Java Spring Boot, powered by a clean Mediator architecture.
- Command-Query Separation (CQS) pattern implementation
- Clean Mediator architecture
- Spring Boot auto-configuration
- Type-safe command and query handling
- Easy integration with Spring Boot applications
- Comprehensive test coverage
- GitHub Actions CI/CD pipeline
To enable automatic updates of code coverage badges, you need to configure GitHub Actions permissions:
- Go to your repository settings
- Navigate to "Actions" → "General"
- Under "Workflow permissions", select:
- "Read and write permissions"
- Check "Allow GitHub Actions to create and approve pull requests"
- Save the changes
This will allow the GitHub Actions workflow to:
- Update code coverage badges
- Commit changes to the repository
- Create and update pull requests
- Java 21
- Maven 3.6+
- Spring Boot 3.4.4+
git clone git@github.com:luismr/spring-commander.git
- First, configure your GitHub token in
~/.m2/settings.xml
:
<settings>
<servers>
<server>
<id>github</id>
<username>YOUR_GITHUB_USERNAME</username>
<password>YOUR_GITHUB_TOKEN</password>
</server>
</servers>
</settings>
Note: If you don't have a GitHub token, you can request one by contacting me on X (@luismachadoreis) or BlueSky (@luismachadoreis.bsky.social).
- Add the GitHub Packages repository to your
pom.xml
:
<repositories>
<repository>
<id>github</id>
<name>Spring Commander GitHub Packages</name>
<url>https://maven.pkg.github.com/luismr/spring-commander</url>
</repository>
</repositories>
- Add the dependency to your
pom.xml
:
<dependency>
<groupId>dev.luismachadoreis.blueprint</groupId>
<artifactId>spring-commander</artifactId>
<version>0.0.3</version>
</dependency>
- First, configure your GitHub token in
~/.gradle/gradle.properties
:
gpr.user=YOUR_GITHUB_USERNAME
gpr.key=YOUR_GITHUB_TOKEN
- Add the GitHub Packages repository to your
build.gradle
:
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/luismr/spring-commander")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
- Add the dependency to your
build.gradle
:
implementation 'dev.luismachadoreis.blueprint:spring-commander:0.0.3'
- Create a command:
public class CreateUserCommand implements Command<User> {
private final String username;
private final String email;
public CreateUserCommand(String username, String email) {
this.username = username;
this.email = email;
}
// Getters
}
- Create a command handler:
@Component
public class CreateUserCommandHandler implements CommandHandler<CreateUserCommand, User> {
@Override
public User handle(CreateUserCommand command) {
// Implementation
return new User(command.getUsername(), command.getEmail());
}
}
- Use the mediator in your service:
@Service
public class UserService {
private final SpringCommanderMediator mediator;
public UserService(SpringCommanderMediator mediator) {
this.mediator = mediator;
}
public User createUser(String username, String email) {
return mediator.send(new CreateUserCommand(username, email));
}
}
- Create a query:
public class GetUserQuery implements Query<User> {
private String username;
// Getters and setters
}
- Create a query handler:
@Component
public class GetUserQueryHandler implements QueryHandler<GetUserQuery, User> {
@Override
public User handle(GetUserQuery query) {
// Implementation
}
}
@Autowired
private SpringMediator mediator;
public void example() {
// Send a command
User user = mediator.send(new CreateUserCommand("username", "email@example.com"));
// Send a query
User foundUser = mediator.send(new GetUserQuery("username"));
}
- Java 21 or later
- Maven 3.8 or later
- Git
git clone https://github.com/luismr/spring-commander-java.git
cd spring-commander-java
mvn clean install
mvn test
Code coverage reports are generated automatically during the build process. You can find the reports in the target/site/jacoco
directory.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
The project uses GitHub Actions for continuous integration and deployment. The workflow includes:
- Building and testing on multiple Java versions
- Code coverage reporting
- Automatic updates of code coverage badges
- Deployment to GitHub Packages
- Configure GitHub authentication in your Maven settings (
~/.m2/settings.xml
):
<settings>
<servers>
<server>
<id>github</id>
<username>YOUR_GITHUB_USERNAME</username>
<password>YOUR_GITHUB_TOKEN</password>
</server>
</servers>
</settings>
- Create a GitHub Personal Access Token (PAT) with the following permissions:
read:packages
write:packages
delete:packages
- Prepare the release:
mvn release:prepare
This will:
- Update version numbers
- Create a Git tag
- Update the SCM information
- Perform the release:
mvn release:perform
This will:
- Checkout the tagged version
- Build and deploy to GitHub Packages
- Create source and Javadoc JARs
- SNAPSHOT versions are deployed to GitHub Packages automatically on each push to main
- Release versions are created manually using the release process
- Version format follows semantic versioning (MAJOR.MINOR.PATCH)
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Luis Machado Reis - luismr
- Spring Boot team for the amazing framework
- Martin Fowler for the CQS pattern
- All contributors and users of this project