2013-05-30 2 views
0

나는 봄 보안 프로젝트를 사용하여 OAuth2 서버 구현을 시도하고있다. 나는 https://github.com/SpringSource/spring-security-oauth에서 자식 프로젝트를 복제했다.기존 프로젝트에 AspectJ 추가하기

예제는 문서화 된대로 작동합니다. 이제 플로우를 추적하기 위해 기존 코드에 AOP를 사용하여 함수 입력/종료를 추가하려고합니다.

  • 추가 클래스 "Watcher.java"(아래 코드)의 pom.xml에
  • 추가 AspectJ의 종속성

    <dependency> 
        <groupId>aspectj</groupId> 
        <artifactId>aspectjrt</artifactId> 
        <version>1.5.3</version> 
    </dependency> 
    <dependency> 
        <groupId>aspectj</groupId> 
        <artifactId>aspectjweaver</artifactId> 
        <version>1.5.3</version> 
    </dependency> 
    
  • 프로젝트 빌드 및

    실행이 들어 나는 다음과 같은 변경을 수행 한
  • 각 기능에 대한 AspectJ 아이콘이 보이지 않음

원본 코드를 많이 변경하지 않고이 방법으로 함수 입력/종료 로깅을 추가 할 수 있습니까?

Watcher.java는 :

package org.springframework.security.oauth.examples.sparklr; 

import java.util.Arrays; 

import org.aspectj.lang.JoinPoint; 
import org.aspectj.lang.annotation.AfterReturning; 
import org.aspectj.lang.annotation.Aspect; 
import org.aspectj.lang.annotation.Before; 
import org.aspectj.lang.annotation.Pointcut; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 

@Aspect 
public class Watcher { 

    @Pointcut("execution(* *(..))") 
    public void watch() { 
    } 

    @Before("watch()") 
    public void preWatch(JoinPoint joinPoint) { 

     if (joinPoint.getArgs().length > 0) { 
      String[] args = new String[joinPoint.getArgs().length]; 

      System.arraycopy(joinPoint.getArgs(), 0, args, 0, 
      joinPoint.getArgs().length); 

      System.out.println("-> " + joinPoint.toShortString() 
        + Arrays.toString(joinPoint.getArgs())); 
     } else { 
      System.out.println("-> " + joinPoint.toShortString()); 
     } 

     System.out.println("Args: " + joinPoint.getArgs().length); 
    } 

    @AfterReturning("watch()") 
    public void postWatch(JoinPoint joinPoint) { 
     System.out.println("<- " + joinPoint.toShortString()); 
    } 
} 

답변

0

당신은

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

    <context:component-scan base-package="..."/> 
    <aop:aspectj-autoproxy /> 
    ... 
</beans> 

어쩌면 당신도 프로젝트에 spring-aop 의존성에 nedd합니다 (자동적으로 주석을 스캔) 봄 구성에서 AspectJ를를 사용하도록 설정해야합니다.

관련 문제