I've finally made it so I would like to share my solution. Maybe someone will need it some day.
I've decided to do the compile time weaving. In my last post I was very close to do it. The aspectj-maven-plugin was simply too old but when I've changed it to 1.4 the weaving process was ok but... not for the CDI:
Code:
org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001437 Normal scoped bean class myPackageName.myClassName is not proxyable because the type is final or it contains a final method static final java.lang.String myPackageName.myClassName.myMethodName_aroundBody0(myPackageName.myClassName.,org.aspectj.lang.JoinPoint).
The problem was finally solved in the AspectJ 1.6.12 (you can find details here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=349149) with the new option of ajc tool which is:
Code:
-Xset:avoidFinal=true
As far as I'm concerned it is not possible to use this option in the current (1.4) version of aspectj-maven-plugin but there is no such problem with ant 1.8.2.
The final solution is adding the following plugin to your <build> tag:
Code:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target xmlns:aspectj="antlib:org.aspectj">
<property name="compile-classpath" refid="maven.compile.classpath"/>
<aspectj:iajc
X="set:avoidFinal=true"
showWeaveInfo="true"
inpath="${project.build.directory}"
aspectpath="${settings.localRepository}/org/springframework/security/spring-security-aspects/${org.springframework.version}/spring-security-aspects-${org.springframework.version}.jar"
destDir="${project.build.outputDirectory}"
classpath="${compile-classpath}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
</plugin>
Now Spring Security works everywhere. The
Code:
<context:load-time-weaver/>
option is no longer needed.