2016-07-27 5 views
0

私は、ロガークラスを使用して休憩コントローラの周りにAroundメソッドを使用しようとしています。私は出力を "コントローラを呼び出す前に"、 "コントローラを呼び出した後など"を取得しますが、私は郵便配達人に返却結果を取得しません。@Around Adviceコントローラでは動作しません。 @ Before、@ Afterなどエラーなしで作業する

@Beforeメソッドと@Afterでコードは正常に動作します。

ReSTコントローラは次のようになります。

@RestController("/") 
public class DummyController { 

@RequestMapping(value="hello",method=RequestMethod.GET) 
public String dummyMethod() { 
    System.out.println("In Controller..."); 
    return "Hello There"; 
    } 
} 

これはAspectクラスです。

@Aspect 
@Component 
public class Logger { 

    @Around("within(DummyController)")//Around Not working.... 
    public void printMessage(ProceedingJoinPoint p) throws Throwable 
    { 
     System.out.println("Before Calling Method..."); 
     p.proceed(); 
     System.out.println("After calling method..."); 
    } 

Bean構成は以下の通りです:

<mvc:annotation-driven /> 
<context:annotation-config></context:annotation-config> 
<context:component-scan base-package="com.aop.test"> </context:component-scan> 

<aop:aspectj-autoproxy></aop:aspectj-autoproxy> 
</beans> 

私の出力は、次のとおりです。

Before Calling Method... 
In Controller... 
After calling method... 

But the webservice output is blank in postman instead of "Hello There". The status is "200 OK" 
The code works as expected with other Advices like @Before,@After... 

コードが間違っていた場所に任意のポインタ?

ありがとうございます。

答えて

0

あなたのアスペクトを以下に変更してください。私がアドバイスをした

@Aspect 
@Component 
public class Logger { 

    @Around("within(DummyController)")//Around Not working.... 
    public Object printMessage(ProceedingJoinPoint p) throws Throwable 
    { 
     System.out.println("Before Calling Method..."); 
     Object result = p.proceed(); 
     System.out.println("After calling method..."); 

     return result; 
    } 

お知らせProceedingJoinPoint

によって返されたオブジェクトを返します
関連する問題