Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Spring Framework FAQ: Top Questions

34. What is the use of Spring Profiles?

Spring Profiles allow you to register different beans or configurations for different environments such as development, testing, and production.

📘 Activation:

  • Use @Profile on config classes or beans.
  • Activate via application.properties or environment variable.

📥 Example:

@Profile("dev")
@Bean
public DataSource devDataSource() {
  return new HikariDataSource();
}

🏆 Expected Output:

Only loaded when 'dev' profile is active.

🛠️ Use Cases:

  • Environment-specific beans and settings.
  • Separate database configs for different stages.