【问题标题】:Spring Profile doesn't work with Aspect annotationSpring Profile 不适用于 Aspect 注释
【发布时间】:2015-09-25 05:15:56
【问题描述】:

我声明了一个只有在“测试”配置文件处于活动状态时才应该运行的方面。 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);
  }
}

春季版:4.1.7.RELEASE
AspectJ 版:1.8.2

【问题讨论】:

  • 你在哪里声明你的MyAspect bean?你的配置是怎样的?

标签: java spring aspectj spring-annotations spring-profiles


【解决方案1】:

要使@Profile 工作,您的类应该是@Component 或@Configuration(不可配置)。尝试使用 @Component 注释类。

【讨论】:

    猜你喜欢
    • 2021-11-15
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 2014-08-31
    • 2016-05-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多