@Autowired 사용

@Autowired 사용

@Autowired 사용전 @Service public class ListController implements Controller { private NoticeService noticeService; public void setNoticeService(NoticeService noticeService){ this.noticeService = noticeService; } }

@Autowired는 스프링에서 제공하는 어노테이션이다. @Autowired는 다음과 같이 쓰일 수 있다. 구문을 꼭 xml 설정파일에 추가해야한다.

beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

@Autowired 사용 @Service public class ListController implements Controller { private NoticeService noticeService; @Autowired public void setNoticeService(NoticeService noticeService){ this.noticeService = noticeService; } }

@Autowired어노테이션을 사용하는 경우

간단히 @Autowired 어노테이션을 사용하면 쉽게 의존성 주입을 받을 수 있게 됩니다.

Class 역시 당연히 Bean으로 등록이 되기위한 @Repository어노테이션이 부여되어 있는것을 주목해야 합니다.

@Repository public class NoticeService { ... }

from http://hhnee.tistory.com/112 by ccl(A) rewrite - 2021-12-13 20:27:34