Sobes.tech
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:

  1. XML configuration — the traditional method where beans and dependencies are described in XML files.

  2. Annotations — a more modern and convenient way, for example, @Component, @Service, @Repository for defining beans, @Autowired for dependency injection.

  3. Java configuration — using classes annotated with @Configuration and methods with @Bean to programmatically define beans.

  4. Configuration via properties — using application.properties or application.yml files to set application parameters.

Example of Java configuration:

@Configuration
public class AppConfig {
    @Bean
    public MyService myService() {
        return new MyServiceImpl();
    }
}
What methods of configuring and setting up components… - sobes.tech