spring-profiles
Configuration and profiles management in Spring Boot 3.x. Covers @Profile, @ConfigurationProperties, property sources, YAML/properties, external configuration, secrets management, and environment-specific beans. USE WHEN: user mentions "spring profiles", "@Profile", "@ConfigurationProperties", "environment configuration", "property sources", "profile groups", "conditional beans" DO NOT USE FOR: feature flags at runtime - consider feature flag libraries, Spring Cloud Config - use `spring-cloud-config` skill
What this skill does
# Spring Profiles & Configuration
## Quick Start
```java
@Configuration
@Profile("dev")
public class DevConfig {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.build();
}
}
@Configuration
@Profile("prod")
public class ProdConfig {
@Bean
public DataSource dataSource() {
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(System.getenv("DATABASE_URL"));
return ds;
}
}
```
---
## Profile Activation
```yaml
# 1. application.yml
spring:
profiles:
active: dev
# 2. Environment variable: SPRING_PROFILES_ACTIVE=prod
# 3. Command line: java -jar app.jar --spring.profiles.active=prod
# 4. JVM property: java -Dspring.profiles.active=prod -jar app.jar
```
### Profile Groups
```yaml
spring:
profiles:
active: production
group:
production:
- prod
- prod-db
- prod-security
development:
- dev
- dev-db
- dev-tools
```
### Profile Expression
```java
@Profile("cloud & kubernetes") // AND
@Profile("dev | test") // OR
@Profile("!prod") // NOT
@Profile("(dev | test) & !integration") // Combined
```
---
## @ConfigurationProperties
```java
@ConfigurationProperties(prefix = "app")
@Validated
public class AppProperties {
@NotBlank
private String name;
@NotNull
private String version;
private final Security security = new Security();
@Validated
public static class Security {
@NotBlank
private String jwtSecret;
@Min(3600)
private long jwtExpiration = 86400;
@NotEmpty
private List<String> allowedOrigins = new ArrayList<>();
}
// Getters and setters
}
// Abilitazione
@Configuration
@EnableConfigurationProperties(AppProperties.class)
public class AppConfig {}
```
```yaml
app:
name: MyApplication
version: 1.0.0
security:
jwt-secret: ${JWT_SECRET}
jwt-expiration: 86400
allowed-origins:
- https://example.com
```
### Immutable Configuration (Record)
```java
@ConfigurationProperties(prefix = "app.mail")
public record MailProperties(
@NotBlank String host,
@Min(1) @Max(65535) int port,
String username,
@DefaultValue("false") boolean starttls
) {}
```
> **Full Reference**: See [properties.md](properties.md) for Property Sources, External Configuration (Config Server, K8s, Vault).
---
## Conditional Beans
```java
@Bean
@ConditionalOnProperty(name = "feature.email.enabled", havingValue = "true")
public EmailService emailService() {
return new RealEmailService();
}
@Bean
@Profile("dev")
public CacheManager devCacheManager() {
return new ConcurrentMapCacheManager();
}
@Bean
@ConditionalOnMissingBean(UserService.class)
public UserService defaultUserService() {
return new DefaultUserService();
}
```
> **Full Reference**: See [conditional.md](conditional.md) for Custom Conditions, Validation, Testing.
---
## Secrets Management
```yaml
spring:
datasource:
password: ${DB_PASSWORD}
app:
security:
jwt-secret: ${JWT_SECRET}
```
> **Full Reference**: See [secrets.md](secrets.md) for Jasypt Encryption, Vault Integration.
---
## Best Practices
| Do | Don't |
|----|-------|
| Use @ConfigurationProperties for structured config | Use @Value for complex config |
| Validate properties with Bean Validation | Skip validation |
| Use profile groups for complex environments | Duplicate configuration |
| Externalize all secrets | Commit secrets to repository |
| Use sensible default values | Require all properties |
---
## Production Checklist
- [ ] Secrets externalized (env vars, Vault)
- [ ] Profiles configured for each environment
- [ ] Validation enabled on all properties
- [ ] Default values for optional properties
- [ ] Profile groups for related config
- [ ] Configuration encrypted where needed
---
## When NOT to Use This Skill
- **Runtime feature flags** - Consider LaunchDarkly, Flipt
- **Centralized config** - Use `spring-cloud-config` skill
- **Secrets only** - Consider HashiCorp Vault directly
---
## Anti-Patterns
| Anti-Pattern | Problem | Solution |
|--------------|---------|----------|
| Secrets in git | Security vulnerability | Use env vars or secrets manager |
| Wrong prefix | Properties not loaded | Verify prefix matches YAML |
| Missing @Validated | Validation ignored | Add @Validated annotation |
| @Value for complex config | Unmaintainable | Use @ConfigurationProperties |
---
## Quick Troubleshooting
| Problem | Diagnostic | Fix |
|---------|------------|-----|
| Properties not loaded | Check prefix | Verify @ConfigurationProperties prefix |
| Profile not active | Check logs at startup | Set spring.profiles.active |
| Binding failed | Check type | Use correct types (Duration, etc.) |
| Env var not resolved | Check naming | Use UPPER_SNAKE_CASE |
---
## Reference Files
| File | Content |
|------|---------|
| [properties.md](properties.md) | Property Sources, External Configuration |
| [conditional.md](conditional.md) | Conditional Beans, Validation, Testing |
| [secrets.md](secrets.md) | Secrets Management, Encryption |
---
## External Documentation
- [Externalized Configuration](https://docs.spring.io/spring-boot/reference/features/external-config.html)
- [Profiles](https://docs.spring.io/spring-boot/reference/features/profiles.html)
Related in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.