0Pricing
Java Academy · Lesson

Bean Wiring: @Component, @Service, @Repository

Use stereotype annotations, define beans with @Bean, and understand component scanning.

Stereotype Annotations

Spring provides stereotype annotations that mark classes as Spring-managed beans and convey their role: @Component (generic), @Service (business logic), @Repository (data access), @Controller/@RestController (web layer).

@Component: Generic Bean

Any class annotated with @Component is detected during component scan and registered as a Spring bean. It is the base for all other stereotypes.

@Component
public class EmailFormatter {
    public String format(String to, String subject) {
        return "To: " + to + "\nSubject: " + subject;
    }
}

All lessons in this course

  1. Auto-Configuration and Spring Boot Starters
  2. Application Properties and Profiles
  3. Bean Wiring: @Component, @Service, @Repository
  4. Constructor Injection and Circular Dependencies
← Back to Java Academy