Loading...
Spring Framework Reference Documentation 7.0.2의 Declaring an Aspect의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
@AspectJ support가 활성화되면, @AspectJ aspect(@Aspect 어노테이션을 가진)을
클래스로 가지는 애플리케이션 컨텍스트에 정의된 어떤 빈이든지 Spring에 의해 자동으로
감지되고 Spring AOP를 구성하는 데 사용됩니다. 다음 두 예제는 그다지 유용하지 않은
aspect에 대해 필요한 최소 단계들을 보여줍니다.
두 예제 중 첫 번째는 애플리케이션 컨텍스트에서 @Aspect로 어노테이션된 빈 클래스를
가리키는 일반적인 빈 정의를 보여줍니다:
1public class ApplicationConfiguration { 2 3 @Bean 4 public NotVeryUsefulAspect myAspect() { 5 NotVeryUsefulAspect myAspect = new NotVeryUsefulAspect(); 6 // Configure properties of the aspect here 7 return myAspect; 8 } 9}
1class ApplicationConfiguration { 2 3 @Bean 4 fun myAspect() = NotVeryUsefulAspect().apply { 5 // Configure properties of the aspect here 6 } 7}
1<bean id="myAspect" class="org.springframework.docs.core.aop.ataspectj.aopataspectj.NotVeryUsefulAspect"> 2 <!-- configure properties of the aspect here --> 3</bean>
두 예제 중 두 번째는 @Aspect로 어노테이션된 NotVeryUsefulAspect 클래스 정의를
보여줍니다:
1@Aspect 2public class NotVeryUsefulAspect { 3}
1@Aspect 2class NotVeryUsefulAspect
Aspects(@Aspect로 어노테이션된 클래스)는 다른 어떤 클래스와 마찬가지로 메서드와
필드를 가질 수 있습니다. 또한 pointcut, advice, introduction(inter-type)
선언들을 포함할 수도 있습니다.
컴포넌트 스캐닝을 통한 aspect 자동 감지<br>Spring XML 설정에서 일반 빈으로 aspect 클래스를 등록하거나,<br>
@Configuration클래스의@Bean메서드를 통해 등록하거나, 또는 다른<br>Spring 관리 빈과 동일하게 클래스패스 스캐닝을 통해 Spring이 자동으로<br>감지하도록 할 수 있습니다. 그러나@Aspect어노테이션만으로는 클래스패스에서의<br>자동 감지에 충분하지 않다는 점에 유의해야 합니다. 그러한 목적을 위해서는<br>별도의@Component어노테이션(또는 Spring의 컴포넌트 스캐너 규칙에 따라<br>자격을 갖는 커스텀 스테레오타입 어노테이션)을 추가해야 합니다.
다른 aspects로 aspects에 advice를 적용할 수 있나요?<br>Spring AOP에서 aspects 자체는 다른 aspects의 advice 대상이 될 수 없습니다.<br>클래스에 있는
@Aspect어노테이션은 그것을 aspect로 표시하고, 따라서<br>auto-proxying에서 제외합니다.
Enabling @AspectJ Support
Declaring a Pointcut