繁体   English   中英

Spring Profile无法与Aspect注释一起使用

[英]Spring Profile doesn't work with Aspect annotation

我声明了仅当“测试”配置文件处于活动状态时才应运行的方面。 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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM