>  기사  >  Java  >  @Autowired는 무엇을 합니까?

@Autowired는 무엇을 합니까?

(*-*)浩
(*-*)浩앞으로
2019-09-09 16:55:459764검색

@Autowired는 클래스 멤버 변수, 메소드 및 생성자를 표시할 수 있는 주석으로, Spring이 Bean 자동 배선 작업을 완료할 수 있도록 합니다.

@Autowired는 무엇을 합니까?

@Autowired는 기본적으로 클래스별 일치를 설정하고 @Qualifier는 빈을 이름별로 어셈블하도록 지정합니다.

일반적인 사용법:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
 
import blog.service.ArticleService;
import blog.service.TagService;
import blog.service.TypeService;
 
@Controller
public class TestController {
 
	//成员属性字段使用 @Autowired,无需字段的 set 方法
	@Autowired
	private TypeService typeService;
	
	
	//set 方法使用 @Autowired
	private ArticleService articleService;
	@Autowired
	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
 
	//构造方法使用 @Autowired
	private TagService tagService;
	@Autowired
	public TestController(TagService tagService) {
		this.tagService = tagService; 
	}
	
}

위 내용은 @Autowired는 무엇을 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 csdn.net에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제