> For the complete documentation index, see [llms.txt](https://organization-bht.gitbook.io/it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://organization-bht.gitbook.io/it/framework/spring/spring-legacy-project/spring-core-annotation.md). Agents can also search and read this documentation through its [MCP server](https://organization-bht.gitbook.io/it/~gitbook/mcp).

# Spring Core 모듈의 주요 Annotation

https\://docs.spring.io/spring-framework/reference/

## 1. 계층 구성 어노테이션

* **@Controller,** **@Service, @Repository, @Component  @RestController(Controller와 ResponseBody결합)**
* 클래스가 웹서비스에서 **Controller/Service/Repository 등의 "역할"을 함을 의미하는 주석**.&#x20;
* `component-scan`에 의해 **servlet이 관리하는 bean객체로 등록**된다

## 2. 자동 의존성 주입 어노테이션

### **1. @Autowired**&#x20;

* **IOC Container**에의해 관리되는 **bean객체를 주입**받는 어노테이션.&#x20;
* root-context.xml에서 설정한 모든 bean객체와, servlet-context.xml에서 설정한 bean객체. 내장 bean객체등 IOC Container 내부의 다양한 Bean객체를 주입받을 수 있다.
* ```java
  @Autowired
  private MemberService mService; // 필드방식 의존성 주입

  //@Autowired 클래스내에 생성자가 1개뿐이라면 @Autowired어노테이션 생략 가능
  public Member(MemberService mService){ // 생성자방식 의존성 주입(권장)
      this.mService = mService;
  }

  @Autowired
  public void setMemberService(MemberService mService){ // setter방식 의존성 주입
      this.mService = mService;
  }
  ```

### 2. @ Value

* 프로퍼티에 값을 주입하기 위해 사용하는 어노테이션

### 3. 기타 어노테이션

* @Qualifier @ Inject @Resource (이름기반 자동주입)

## 3. 빈 등록 및 설정 어노테이션

* SpringBoot와 같이 java class기반 스프링 프레임워크 설정시 사용되는 어노테이션들로, 현재 레거시에서는 사용하지 않는다.

### 1. @Configuration

* 클래스가 스프링 설정 클래스임을 의미
* 내부에 @Bean을 사용하여 Bean을 등록할 수 있다.
* ApplicationContext에 의해 스프링 설정 클래스로 인식된다.&#x20;
* 스프링 설정 xml파일의 `<beans >` 태그의 역할을 한다.

### 2. @Bean&#x20;

* 메서드에 붙일 수 있는 어노테이션으로,  반환 되는객체를 빈으로 등록해주는 기능을 한다
* 메서드의 이름이 Bean객체의 이름으로 사용된다.
* EX)

```
@Configuration // 설정 클래스임을 의미.
public class Config{ 
    @Bean
    public Service service() {
        return new ServiceImpl(); // 반환되는 객체 bean객체로 등록
    }
}
```

### 3. @ComponentScan

* < context:componentscan>의 역할을 대신하는 태그.
* 어노테이션이 설정된 하위 패키지의 클래스를 스캔한다.
