Repository2 Spring Annotation 11. @Repository Spring Annotation 11. @Repository @Repository 예제 package com.example.demo; import org.springframework.stereotype.Repository; @Repository public class MyRepository { public String getData() { // 데이터베이스나 다른 저장소로부터 데이터를 가져오는 로직 return "Sample data"; } } 예제에서 MyRepository 클래스는 데이터 액세스 로직을 포함하며 @Repository 어노테이션이 붙어 있어서 스프링 컨테이너에 의해 관리됩니다. MyRepository 클래스의 getData() 메서드는 데이터베이스나 다른 저장소로부터 데이터를 가져오는 로직을 수행합니다. @Repository는 데이터 액세스 계층.. 2023. 4. 19. Spring Annotation 9. @Component Spring Annotation 9. @Component 스프링 프레임워크에서는 클래스를 빈(Bean)으로 등록하여 의존성 주입(Dependency Injection)과 관리를 쉽게 할 수 있도록 어노테이션을 사용합니다. @Component란? @Component는 스프링의 주요 어노테이션 중 하나로, 클래스를 스프링 빈으로 등록하려 할 때 사용합니다. 이 어노테이션을 사용하면 스프링이 해당 클래스의 인스턴스를 생성하고, 관리 및 의존성 주입을 수행할 수 있습니다. 스프링 컨테이너는 @Component가 붙은 클래스를 찾아서 빈으로 등록하며, 이 과정은 컴포넌트 스캔(Component Scan)이라고 합니다. @Component 예제 package com.example.demo; import org.springframework.stereotype.Compone.. 2023. 4. 19. 이전 1 다음