Ortamlar için Profiller
Profillerle her ortama uygun yapılandırmaya geçin.
Ortamlar için Profiller, CoddyKit'te ücretsiz bir Spring Boot 4 Microservices & REST APIs dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Spring Boot 4 Microservices & REST APIs öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Why Profiles Exist
Real applications run in several environments — local, dev, staging, production — each needing different datasources, log levels, and feature toggles. Profiles let one codebase carry many configurations and activate the right set at runtime.
A profile is just a named label. Beans and property files can be tagged so they apply only when that profile is active.
Profile-Specific Property Files
Boot automatically loads application-{profile}.yml on top of the base application.yml. The profile file overrides matching keys while inheriting everything else.
# application.yml (base, always loaded)
spring:
jpa:
show-sql: false
# application-dev.yml (loaded when dev active)
spring:
jpa:
show-sql: true
datasource:
url: jdbc:h2:mem:devdbActivating a Profile
Set spring.profiles.active to choose which profiles run. You can do this in a file, as an environment variable, or on the command line.
# Command line
java -jar app.jar --spring.profiles.active=prod
# Environment variable
export SPRING_PROFILES_ACTIVE=prod
# Multiple profiles
java -jar app.jar --spring.profiles.active=prod,metricsConditional Beans with @Profile
@Profile on a bean or configuration class makes it register only when that profile is active. This is ideal for swapping implementations between environments.
@Configuration
public class PaymentConfig {
@Bean
@Profile("prod")
public PaymentGateway liveGateway() {
return new StripeGateway();
}
@Bean
@Profile("!prod")
public PaymentGateway fakeGateway() {
return new InMemoryGateway();
}
}Profile Expressions
The @Profile value supports simple logic: ! for NOT, & for AND, and | for OR. Group expressions with parentheses.
@Profile("!prod") // anything except prod
@Profile("prod & metrics") // both active
@Profile("dev | test") // either active
@Profile("prod & (eu | us)") // groupedThe Default Profile
When no profile is active, Spring enables the implicit default profile. You can target it explicitly with @Profile("default") for fallback beans used during plain local runs.
@Bean
@Profile("default")
public DataSeeder localSeeder() {
return new SampleDataSeeder();
}Profile Groups
A profile group bundles several profiles under one name, so activating the group activates them all. Great for composing cross-cutting concerns.
spring:
profiles:
group:
production:
- prod
- metrics
- swagger-off
# Now: --spring.profiles.active=production turns on all threeIncluding Profiles
spring.profiles.active sets the primary profiles, while spring.profiles.include adds extra ones unconditionally, regardless of which primary profile is selected.
spring:
profiles:
include:
- common-logging
- auditInspecting Active Profiles at Runtime
You can read active profiles from the Environment bean. This is useful for guard logic or for logging which configuration is live.
@Component
public class StartupLogger {
private final Environment env;
public StartupLogger(Environment env) { this.env = env; }
@PostConstruct
void log() {
System.out.println("Active: "
+ String.join(",", env.getActiveProfiles()));
}
}Profiles in Tests
In integration tests, annotate the class with @ActiveProfiles to force a specific configuration, such as an in-memory database profile.
@SpringBootTest
@ActiveProfiles("test")
class OrderServiceTest {
// loads application-test.yml + @Profile("test") beans
}Common Pitfalls
Watch for these mistakes:
- Forgetting to set
spring.profiles.activein production, so dev defaults leak in - Putting secrets in
application-dev.ymland committing it - Overusing
@Profilewhere a simple property toggle would do
Quick Check
Test your grasp of profile expressions.
Recap
Profiles tailor one codebase to many environments.
application-{profile}.ymloverrides base config- Activate via
spring.profiles.active(file, env var, or CLI) @Profileconditionally registers beans, with!,&,|expressions- Profile groups bundle related profiles
- Use
@ActiveProfilesin tests
Sıkça Sorulan Sorular
“Ortamlar için Profiller” dersi ücretsiz mi?
Evet — “Ortamlar için Profiller” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Spring Boot 4 Microservices & REST APIs kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.
“Ortamlar için Profiller” dersinde ne öğreneceğim?
Profillerle her ortama uygun yapılandırmaya geçin. Spring Boot 4 Microservices & REST APIs ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Spring Boot 4 Microservices & REST APIs öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Spring Boot 4 Microservices & REST APIs, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“Ortamlar için Profiller” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Spring Boot 4 Microservices & REST APIs dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Spring Boot 4 Microservices & REST APIs dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- application.properties ve YAML
- Ortamlar için Profiller
- @ConfigurationProperties ile Tür Güvenli Yapılandırma
- Harici ve Geçersiz Kılan Yapılandırma