Junior — Middle
What annotations are you familiar with for defining configuration?
sobes.tech AI
Answer from AI
In Java, annotations from the Spring Framework and other libraries are often used to define configuration. The main ones include:
@Configuration— indicates a class that contains bean definitions.@Bean— marks a method that creates and returns a bean.@ComponentScan— specifies packages to scan for components.@PropertySource— includes an external configuration file.@Value— injects a value from the configuration into a field.
Example:
@Configuration
@PropertySource("classpath:application.properties")
public class AppConfig {
@Bean
public MyService myService() {
return new MyService();
}
}