1. <context:componet-scan>

context: componet-scan base-package="com.controller"
특정 패키지안의 클래들을 스캔하고 빈 인스턴스를 생성한다. 
base-package 패키지의 내의 클래스들을 스캔하며 아래 어노테이션을 찾는다.
스캔을 통해 빈이 등록될 경우 자동 의존 설정이 필요하다. 
@Component
@Repository( ddd에서의 Repository )
@Service ( ddd에서의 Service )
@Controller 
@required
@configuration : 여러 클래스에 빈 정보를 나누어 설정 할 수 있다. 

 context:component-scan은 암시적으로  context:component-config를 호출하여 Bean에 대한 주석을 활성화한다. 


 


2.<mvc: annotation-driven>
스프링  mvc컴포넌트들은 그것을 디폴트 설정을 가지고 활성화 하기 위해 사용된다. 
context:component-scan을 사용하면 빈을 생성하기 위해 mvc:annotation-driven을포함시키지 않아도 mvc어플리케이션은 잘 동작한다. 
하지만 이 태그를 사용함으로써 @Controller에게 요청을 전파하기위해 요구되는 HandlerMapping와 HandlerAdapter를 등록한다.  게다가 클래스 패스상에 존재하는 디폴트작업들을 한다. 
  • Using the Spring 3 Type ConversionService as a simpler and more robust alternative to JavaBeans PropertyEditors
  • Support for formatting Number fields with @NumberFormat
  • Support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath
  • Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath
  • Support for reading and writing XML, if JAXB is on the classpath
  • Support for reading and writing JSON, if Jackson is on the classpath
이 태그를 사용하지않으면 xml에서 bean으로 RequestMappingHandlerMaggping , RequestMappingHandlerAdapter를 등록해주어야한다. 
 
-<mvc:default-servlet-handler>
  jsp와 특정확장자를 가진 URL말고는 모두 dispatchServlet이 다 받는다. 등록된 핸들러 매핑 전략을 이용해 컨트롤러 매핑에서 찾는다.  담당하는 URL은 컨트롤러로 넘어가나 /js/jquery.js 처럼 매핑안되는 url은 DefaultServletHttpRequestHandler이 담당한다. 이 컨트롤러는 /**로 매핑되어있다. 그리고 default라 우선순위가 제일 낮다. 사실 DefaultServletHttpRequestHandler는 서버가 제공하는 디폴트 서블릿으로 넘기는 작업을 하는데 이떄 스프링이 처리못하는 URl을 담당한다 
디폴트 서블릿은 서버마다 이름이 다르다.톰캣, 제티는 이름이 default, Resin은 resin-file, WebLogic은 FileServlet, WebSphere는 SimpleFileServlet이다
annotation-driven 태그가 등록하는 RequestMappingHandlerMapping의 우선순위가 default-servlet-handler 태그가 등록하는 simpleUrlHandlerMappging의 우선순위보다 높다. 
RequestMappingHandlerMapping 다음 SimpleUrlHandlerMappging 확인한다. 

3.<context : annotation-config>
= bean class : Autowire , Common , Qualifier + AnnotationBeanPostProcecssor

어플리케이션 컨텍스트안에 이미 등록된 빈의 어노테이션의 활성화를 위해 사용된다. 

@Autowired : 의존개체를 자동설정할때 타입을 이용하여 의존하는 객체를 주입한다. 설정위치는 생성자, 필드, 메소드이며 null값 유지시 required = false
@Qualifier :  @Autowired과 함께 사용된다. 동일타입 빈객체에 value 부여로 구별할수있다.
@Resource : @Autowired과 같은역할이지만 @Autowired는 타입으로 @Resource는 이름으로 연결한다. 설정위치는 프로퍼티, setter메소드이다.
 속성의 name은 빈객체의 이름이며 name 지정없을경우 필드이름이나 프로퍼티 이름을 사용한다. 
@postConstruct  의존하는 객체의 초기화  CommonAnnotationBeanPostProcessor 클래스를 빈으로 등록시켜줘야 한다
@PreConstruct  컨테이너에서 객체를 제거하기 전에 해야할작업을 수행하기 위해 사용된다. 
@inject  +  @named:  @Autowired은 required속성을 이용해서 필수 여부를 지정할 수 있는 것과 달리 inject 애노테이션은 반드시 사용할 빈이 존재해야한다. 












'STUDY > SPRING' 카테고리의 다른 글

TRANSACTION  (0) 2018.11.06
MVC  (0) 2018.11.02
[코드로 배우는 스프링 웹프로젝트]  (0) 2018.10.31
스프링 컨테이너와 빈  (0) 2018.10.30
[코드로 배우는 스프링 웹프로젝트] PART 1. 프로젝트의 기본구조 구성  (0) 2018.10.29

+ Recent posts