@InputOutputProxy
Posted by Bruce Tsai
說明
透過 AOP 記錄呼叫的方法中輸入及輸出的內容。可設定僅記錄輸出或僅記錄輸入內容。需在 spring 設定中設定 AOP 相關的設定,配合 InputOutputAdvice
使用。
範例
- spring 設定檔
<aop:config proxy-target-class="true">
<aop:pointcut
id="inputOutputProxy"
expression="execution(* com.fet.crm.eservice..*.*(..))
and (@within(foundation.core.generic.annotation.aop.InputOutputProxy)
or @annotation(foundation.core.generic.annotation.aop.InputOutputProxy))"
/>
<aop:advisor
advice-ref="inputOutputAdvice"
pointcut-ref="inputOutputProxy" />
</aop:config>
<bean id="inputOutputAdvice"
class="foundation.core.generic.aop.InputOutputAdvice">
<property name="enabled" value="true" />
</bean>
- 程式用例
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class Executor {
@InputOutputProxy
public CharSequence execute(String name, Date date) {
return String.format("%s=%s", name, date);
}
}
public class Program
public static void main(String[] args) {
Context context = Contexts.Load();
Executor executor = context.getBean(Executor.class);
executor.execute("bruce", new Date());
}
}
輸出結果
輸入參數[Executor.execute()] => {
[java.lang.String] "bruce"
[java.util.Date] "Dec 12, 2015 7:14:51 PM"
}
回傳值[Executor.execute()] => [java.lang.CharSequence]
"bruce\u003dSat Dec 12 19:14:51 CST 2015"