1

「テスト」プロファイルがアクティブな場合にのみ実行する必要があるアスペクトを宣言しました。Spring は@Profile アノテーションを考慮していないようで、「テスト」プロファイルがアクティブ化されているかどうかにかかわらず、その側面を実行します。

以下はコードブロックです。

import org.springframework.context.annotation.Profile;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
@Configurable
@Profile("test")
public class MyAspect {

  @Autowired
  private MyService service;

  @Pointcut("execution(private * method(..)) && args(table,..)")
  public void myPointcut(StatsParameterTable table) {}

  @AfterReturning(pointcut = "myPointcut(table)")
  public void intercept(StatsParameterTable table) {
    myService.doStuff(table);
  }
}

Spring バージョン: 4.1.7.RELEASE
AspectJ バージョン: 1.8.2

4

1 に答える 1

-1

@Profile を機能させるには、クラスを @Component または @Configuration (構成不可) にする必要があります。@Component でクラスにアノテーションを付けてみてください。

于 2015-07-07T16:07:26.870 に答える