我正在使用 spring-security 3.2.4.RELEASE 、 spring-security-aspects 3.2.4.RELEASE 、AspectJ maven 插件版本 1.6、Java 7。
我使用AspectJ的编织而不是SpringAOP,因此我的aspectj maven插件如下所示:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<Xlint>ignore</Xlint>
<showWeaveInfo>true</showWeaveInfo>
<source>${java.version}</source>
<target>${java.version}</target>
<complianceLevel>${org.aspectj-version}</complianceLevel>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</plugin>
我还有另一个方面,如下所示:
package com.mycompany.fw.app.config;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.security.core.parameters.DefaultSecurityParameterNameDiscoverer;
import com.mycompany.fw.security.Integration;
@Aspect
@DeclarePrecedence("IntegrationAspects*,*")
public class IntegrationAspects {
ParameterNameDiscoverer parameterNameDiscoverer = new DefaultSecurityParameterNameDiscoverer();
@Pointcut("(execution(* com.mycompany..*(..))) && @annotation(integrate) ")
public void integratePointCut(Integration integrate) {
}
/**
* TODO: cache
*
* @param jp
* @param integrate
* @throws Throwable
*/
@Around("integratePointCut(integrate)")
public Object integrate(final ProceedingJoinPoint pjp, Integration integrate) throws Throwable {
Object res = pjp.proceed();
return res;
}
}
我需要的是将上述(集成方面)放在任何其他方面(包括 Spring 的安全方面)之前
正如您所看到的,我使用 @DeclarePrecedence
进行了尝试(我也在 .aj 文件中使用 declare precedence : IntegrationAspects*,*
进行了尝试),不幸的是,没有成功.
有人可以指导我如何定义方面调用顺序吗?
最佳答案
问题是您在 @DeclarePrecedence
中没有使用普通方面名称 IntegrationAspects
,而是使用 clown 字符 *
。在这种情况下,您需要使用完全限定的类名或创建相同的 clown 。
不起作用:
@DeclarePrecedence("IntegrationAspects*, *")
作品:
@DeclarePrecedence("IntegrationAspects, *")
@DeclarePrecedence("com.mycompany.fw.security.Integration.IntegrationAspects, *")
@DeclarePrecedence("com.mycompany.fw.security.Integration.IntegrationAspects*, *")
@DeclarePrecedence("*..IntegrationAspects*, *")
等等。顺便说一句,在类名中使用大写的包名和复数看起来真的很难看。
我是 AspectJ 专家,而不是 Spring 用户,所以我无法告诉您声明优先级是否也会影响 Spring 提供的方面。它还可能取决于它们是使用 native AspectJ 还是 Spring-AOP(基于代理的“AOP lite”)实现。
关于spring-security - Aspectj 和 Spring Security 方面 - 建议执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688415/