springboot — GitHub Copilot rule: Spring Boot conventions
A Copilot rule that pins down how Spring Boot code gets written: injection, config, logging and build checks.
.github/instructions/springboot.instructions.mdWhat springboot does
The rule attaches to GitHub Copilot and covers files matching **/*.java and **/*.kt. It lists conventions for Spring Boot work: constructor injection for required dependencies, fields declared private final, externalized settings in application.yml, Spring profiles for dev, test and prod, and type-safe binding through @ConfigurationProperties. Secrets belong in environment variables or a secret management system.
Packages are grouped by feature or domain instead of by layer. Controllers stay thin, business logic lives in @Service classes, and services hold no state. Logging goes through SLF4J with parameterized messages; concrete backends such as Logback or Log4j2 and System.out.println() are off the table. To block SQL injection the rule points at Spring Data JPA or NamedParameterJdbcTemplate, and request bodies plus parameters are validated with JSR-380 annotations (@NotNull, @Size) and BindingResult.
Once code changes land, the rule asks for a build check: mvn clean package on Maven, ./gradlew build on Gradle, with tests passing as part of it. A command table maps run, build, test and packaging steps for both tools, including JAR and container image output. No Maven or Gradle wrapper in the project means those steps have nothing to run.
What it helps with
- keep Copilot output consistent across a Spring Boot codebase
- move settings into
application.ymlwith profiles - pull secrets out of source into environment variables
- swap
System.out.println()for parameterized SLF4J calls - confirm the build and tests still pass after edits
Example prompts for the agent
- Add a new REST controller for orders following the springboot rule
- Move this service's config into
application.ymlwith dev and prod profiles - Check that the project still builds with
./gradlew buildafter the changes
How to install springboot
Manually: put the files in place
.github/instructions/springboot.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.claude/rules/springboot.mdThe paths frontmatter field limits the files: move applyTo from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/springboot.mdcFrontmatter: description, globs, alwaysApply. Move applyTo from the source into globs, or the rule will not attach on its own
Manually: put the files in place
.devin/rules/springboot.mdManually: put the files in place
.clinerules/springboot.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about springboot
How do I install springboot in GitHub Copilot?
Copy the rule file to .github/instructions/springboot.instructions.md in your repository root. Copilot picks it up for **/*.java and **/*.kt files.
What does springboot do?
It is a GitHub Copilot rule with Spring Boot guidelines covering dependency injection, configuration, package layout, logging, input safety and build verification.
Which files does the rule apply to?
The applyTo field sets the scope to **/*.java, **/*.kt. Other file types are left alone.
Source text
springboot.instructions.md · MIT
---
description: 'Guidelines for building Spring Boot base applications'
applyTo: '**/*.java, **/*.kt'
---
# Spring Boot Development
## General Instructions
- Make only high confidence suggestions when reviewing code changes.
- Write code with good maintainability practices, including comments on why certain design decisions were made.
- Handle edge cases and write clear exception handling.
- For libraries or external dependencies, mention their usage and purpose in comments.
## Spring Boot Instructions
### Dependency Injection
- Use constructor injection for all required dependencies.
- Declare dependency fields as `private final`.
### Configuration
- Use YAML files (`application.yml`) for externalized configuration.
- Environment Profiles: Use Spring profiles for different environments (dev, test, prod)
- Configuration Properties: Use @ConfigurationProperties for type-safe configuration binding
- Secrets Management: Externalize secrets using environment variables or secret management systems
### Code Organization
- Package Structure: Organize by feature/domain rather than by layer
- Separation of Concerns: Keep controllers thin, services focused, and repositories simple
- Utility Classes: Make utility classes final with private constructors
### Service Layer
- Place business logic in `@Service`-annotated classes.
- Services should be stateless and testable.
- Inject repositories via the constructor.
- Service method signatures should use domain IDs or DTOs, not expose repository entities directly unless necessary.
### Logging
- Use SLF4J for all logging (`private static final Logger logger = LoggerFactory.getLogger(MyClass.class);`).
- Do not use concrete implementations (Logback, Log4j2) or `System.out.println()` directly.
- Use parameterized logging: `logger.info("User {} logged in", userId);`.
### Security & Input Handling
- Use parameterized queries | Always use Spring Data JPA or `NamedParameterJdbcTemplate` to prevent SQL injection.
- Validate request bodies and parameters using JSR-380 (`@NotNull`, `@Size`, etc.) annotations and `BindingResult`
## Build and Verification
- After adding or modifying code, verify the project continues to build successfully.
- If the project uses Maven, run `mvn clean package`.
- If the project uses Gradle, run `./gradlew build` (or `gradlew.bat build` on Windows).
- Ensure all tests pass as part of the build.
## Useful Commands
| Gradle Command | Maven Command | Description |
|:--------------------------|:----------------------------------|:----------------------------------------------|
| `./gradlew bootRun` |`./mvnw spring-boot:run` | Run the application. |
| `./gradlew build` |`./mvnw package` | Build the application. |
| `./gradlew test` |`./mvnw test` | Run tests. |
| `./gradlew bootJar` |`./mvnw spring-boot:repackage` | Package the application as a JAR. |
| `./gradlew bootBuildImage`|`./mvnw spring-boot:build-image` | Package the application as a container image. |
© github · MIT · github/awesome-copilot