Junior — Middle
What methods of configuring and setting up components in Spring Framework do you know?
sobes.tech AI
Answer from AI
In the Spring Framework, there are several ways to configure and set up components:
-
XML configuration — the traditional method where beans and dependencies are described in XML files.
-
Annotations — a more modern and convenient way, for example,
@Component,@Service,@Repositoryfor defining beans,@Autowiredfor dependency injection. -
Java configuration — using classes annotated with
@Configurationand methods with@Beanto programmatically define beans. -
Configuration via properties — using
application.propertiesorapplication.ymlfiles to set application parameters.
Example of Java configuration:
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}