Annotation

    [JSP & Servlet] Servlet 맵핑

    [JSP & Servlet] Servlet 맵핑

    JSP와 Servlet을 실행해 봤을때 JSP는 주로 MVC(Model View Controller)패턴에서 View를 만들어줄 때 사용하고 Servlet을 Model과 Controller를 만들때 사용합니다. 또 Servlet을 만들때 URL mapping을 해주었는데요. Servlet 맵핑이란 무었일까요?? 브라우저에서 요청을 보낼때 서블릿을 쉽게 구분할수 있는 요소가 필요합니다. 하지만 위의 그림처럼 full path를 입력해야 구분이 될 경우 복잡할 뿐더러 보안에도 상당히 취약할수 있겠죠. 그래서 path를 mapping하여 좀더 간결한 URL을 만들어줍니다. Servlet Mapping을 하는 방법은 크게 2가지로 web.xml파일을 이용한 매핑이 있고 Java annotation을 활용한 매핑..

    [Spring] AOP(@Component)

    [Spring] AOP(@Component)

    패키지구조 Student.java package com.test06; public interface Student { void classWork(); } Man.java package com.test06; import org.springframework.stereotype.Component; @Component public class Man implements Student { @Override public void classWork() { System.out.println("컴퓨터를 켜서 뉴스본다."); } } Woman.java package com.test06; import org.springframework.stereotype.Component; @Component public class Woma..

    [Spring] Annotation(@Component)

    [Spring] Annotation(@Component)

    @Component 클래스에 선언하여 해당 클래스를 자동으로 bean 등록. bean의 이름은 해당 클래스의 이름(첫글자 소문자) 범위는 디폴트로 singleton. @Scope로 지정 가능 ​ Annotation코드만 간단하게 보겠습니다. 우선 SamsongTv클래스와 IgTv클래스가 있다고 치면 @Component public class IgTv implements TV { } 해당 어노테이션은 IgTv를 Bean객체로 등록해주는 역할입니다. xml에서는 위와 같은 코드가 되겠네요! IgTV igTV = new IgTV(); 또 일반적인 자바 코드로는 위와 같은 코드입니다. ​ @Component("samsong") public class SamsongTv implements TV { } 해당 어노테..

    [Spring] Annotation(@Autowired, @Qualifier)

    [Spring] Annotation(@Autowired, @Qualifier)

    @Autowired Autowired annotation은 spring에서 의존관계를 자동으로 설정할 때 사용한다. 이 어노테이션은 생성자, 필드, 메서드 세곳에 적용이 가능하며 타입을 이용한 프로퍼티 자동 설정기능을 제공한다. 즉, 해당 타입의 빈 객체가 없거나 2개 이상일 경우 예외를 발생시킨다. ​ @Qualifier @Autowired annotation이 타입 기반이기 떄문에 2개 이상의 동일타입 빈 객체가 존재할 시 특정 빈을 사용하도록 선언한다. @Qualifier("beanName")의 형태로 @AutoWired와 같이 사용하며 메서드에서 두 개 이상의 파라미터를 사용할 경우에는 파라미터 앞에 선언해야 한다. ​ 좀 더 많은 어노테이션에 대한 설명은 Spring_14 스프링 어노테이션에 있..

    [Spring] Spring Annotation(스프링 어노테이션)

    [Spring] Spring Annotation(스프링 어노테이션)

    Spring annotation - 어노테이션은 자바 1.5부터 지원 - 스프링은 어노테이션을 이용하여 빈과 관련된 정보를 설정할 수 있다. - 일반적으로 @로 시작하는 것이 어노테이션이다. ​ Spring Framework에서 annotation을 사용하려면 다음과 같은 설정들을 필요로 한다. 1. CommonAnnotationBeanPostProcessor 클래스를 설정파일에 bean 객체로 등록한다. ​ 2. 태그를 이용한다. @Autowired, @Required, @Resource, @PostConstructor, @PreDestroy 등의 annotation을 자동 처리해주는 bean post processor ​ 3. 태그를 이용한다. @Component, @Controller, @Servi..