Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 0eaf133

Browse files
committed
Merge pull request #25 from astefan/master
Repro project for issues related to SPR-9876
2 parents 4bbcbdc + 71eb763 commit 0eaf133

File tree

14 files changed

+283
-0
lines changed

14 files changed

+283
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>example</groupId>
5+
<artifactId>aop-ordering-test</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
8+
<properties>
9+
<spring.version>3.1.1.RELEASE</spring.version>
10+
<aspectj.version>1.6.12</aspectj.version>
11+
</properties>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>junit</groupId>
16+
<artifactId>junit</artifactId>
17+
<version>4.7</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-core</artifactId>
22+
<version>${spring.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-context</artifactId>
27+
<version>${spring.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework</groupId>
31+
<artifactId>spring-aop</artifactId>
32+
<version>${spring.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.aspectj</groupId>
36+
<artifactId>aspectjrt</artifactId>
37+
<version>${aspectj.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.aspectj</groupId>
41+
<artifactId>aspectjweaver</artifactId>
42+
<version>${aspectj.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>cglib</groupId>
46+
<artifactId>cglib-nodep</artifactId>
47+
<version>2.2</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework</groupId>
51+
<artifactId>spring-test</artifactId>
52+
<version>${spring.version}</version>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-compiler-plugin</artifactId>
61+
<version>2.3.2</version>
62+
<configuration>
63+
<source>1.6</source>
64+
<target>1.6</target>
65+
<encoding>UTF-8</encoding>
66+
</configuration>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:aop="http://www.springframework.org/schema/aop"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
7+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
9+
10+
11+
<bean id="checkedInterfaceImpl" class="example.CheckedInterfaceImpl" />
12+
13+
<aop:aspectj-autoproxy />
14+
15+
<context:component-scan base-package="example.aop" />
16+
17+
</beans>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example;
2+
3+
public interface CheckedInterface {
4+
5+
void checkedMethod();
6+
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package example;
2+
3+
import example.annotation.AfterAnnotation;
4+
import example.annotation.BeforeAnnotation;
5+
6+
public class CheckedInterfaceImpl implements CheckedInterface {
7+
8+
@Override
9+
@BeforeAnnotation
10+
@AfterAnnotation
11+
public void checkedMethod() {
12+
System.out.println("checkedMethod");
13+
}
14+
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example.annotation;
2+
3+
import static java.lang.annotation.ElementType.METHOD;
4+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
5+
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.Target;
8+
9+
@Target(METHOD)
10+
@Retention(RUNTIME)
11+
public @interface AfterAnnotation {
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package example.annotation;
2+
3+
import static java.lang.annotation.ElementType.METHOD;
4+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
5+
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.Target;
8+
9+
@Target(METHOD)
10+
@Retention(RUNTIME)
11+
public @interface BeforeAnnotation {
12+
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package example.aop;
2+
3+
import org.aspectj.lang.annotation.After;
4+
import org.aspectj.lang.annotation.Aspect;
5+
import org.springframework.core.Ordered;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
@Aspect
10+
public class CheckAfterAspect implements Ordered {
11+
private static final int ORDER = CheckPrecedence.HIGHER_PRECEDENCE;
12+
13+
@After("execution(@example.annotation.AfterAnnotation * *(..))")
14+
public void checkAfter() {
15+
System.out.println(ORDER + " - checkAfter");
16+
}
17+
18+
@Override
19+
public int getOrder() {
20+
return ORDER;
21+
}
22+
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package example.aop;
2+
3+
import org.aspectj.lang.annotation.After;
4+
import org.aspectj.lang.annotation.Aspect;
5+
import org.springframework.core.Ordered;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
@Aspect
10+
public class CheckAnotherAfterAspect implements Ordered {
11+
private static final int ORDER = CheckPrecedence.NORMAL_PRECEDENCE;
12+
13+
@After("execution(@example.annotation.AfterAnnotation * *(..))")
14+
public void checkAnotherAfter() {
15+
System.out.println(ORDER + " - checkAnotherAfter");
16+
}
17+
18+
@Override
19+
public int getOrder() {
20+
return ORDER;
21+
}
22+
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package example.aop;
2+
3+
import org.aspectj.lang.annotation.Aspect;
4+
import org.aspectj.lang.annotation.Before;
5+
import org.springframework.core.Ordered;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
@Aspect
10+
public class CheckBeforeAspect implements Ordered {
11+
private static final int ORDER = CheckPrecedence.LOWER_PRECEDENCE;
12+
13+
@Before("execution(@example.annotation.BeforeAnnotation * *(..))")
14+
public void checkBefore() {
15+
System.out.println(ORDER + " - checkBefore");
16+
17+
throw new RuntimeException("checkBefore exception");
18+
}
19+
20+
@Override
21+
public int getOrder() {
22+
return ORDER;
23+
}
24+
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example.aop;
2+
3+
public interface CheckPrecedence {
4+
int HIGHER_PRECEDENCE = 0; // far from pointcut
5+
int NORMAL_PRECEDENCE = 1;
6+
int LOWER_PRECEDENCE = 2; // near to pointcut
7+
}

0 commit comments

Comments
 (0)