Sobes.tech
Junior — Middle

What methods can you use to implement component configuration description in Spring Framework?

sobes.tech AI

Answer from AI

In the Spring Framework, component configuration can be implemented in several ways:

  1. XML configuration — the traditional method where components and their dependencies are described in XML files.
<bean id="myService" class="com.example.MyService" />
  1. Java configuration (annotations @Configuration and @Bean) — configuration through Java classes, allowing the use of type safety and refactoring benefits.
@Configuration
public class AppConfig {
    @Bean
    public MyService myService() {
        return new MyService();
    }
}
  1. Automatic component scanning (@Component, @Service, @Repository, @Controller) — annotating classes for automatic detection and registration in the Spring context.
@Service
public class MyService {
    // ...
}
  1. Using profiles (@Profile) — for defining configurations activated in different environments.

These methods can be combined depending on project requirements.

What methods can you use to implement component… - sobes.tech