我使用的是spring security 3.2.4.RELEASE,spring security方面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
,而是使用了一个小丑字符*
。在这种情况下,您需要使用一个完全限定的类名或创建相同类名的小丑。
不工作:
@DeclarePrecedence("IntegrationAspects*, *")
作品:
@DeclarePrecedence("IntegrationAspects, *")
@DeclarePrecedence("com.mycompany.fw.security.Integration.IntegrationAspects, *")
@DeclarePrecedence("com.mycompany.fw.security.Integration.IntegrationAspects*, *")
@DeclarePrecedence("*..IntegrationAspects*, *")
等等。顺便说一句,在类名中使用大写的包名和复数看起来真的很难看。
我是AspectJ专家,而不是Spring用户,所以我不能告诉您声明优先级是否也会影响Spring提供的方面。这也可能取决于它们是使用本机AspectJ还是Spring AOP(基于代理的"AOP lite")实现的。