Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Spring Framework FAQ: Top Questions

19. What is PropertySource in Spring and how is it used?

@PropertySource is an annotation used to declare a property file as a source for externalized configuration in a Spring application context.

πŸ—ΊοΈ Steps:

  1. Create a .properties file with config values.
  2. Use @PropertySource to load it.
  3. Use @Value to inject properties.

πŸ“₯ Example:

@Configuration
@PropertySource("classpath:appconfig.properties")
public class AppConfig {

  @Value("${app.name}")
  private String appName;
}

πŸ† Expected Output:

app.name property is loaded and injected into the field.

πŸ› οΈ Use Cases:

  • Loading custom external config files.
  • Separating configuration from codebase.