Skip to content

Commit 9de2d80

Browse files
committed
Added the @AfterThrowing sample code
1 parent da8ffe6 commit 9de2d80

File tree

8 files changed

+13
-15
lines changed

8 files changed

+13
-15
lines changed

spring-aop-01-@Before/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
11-
<artifactId>spring-aop-01-@Before</artifactId>
11+
<artifactId>spring-aop-01-Before</artifactId>
1212
<description>Spring AOP - @Before advice example</description>
1313

1414
<dependencies>

spring-aop-03-@AfterReturning/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
11-
<artifactId>spring-aop-03-@AfterReturning</artifactId>
12-
<description>Spring AOP - @AfterReturning advice example</description>
11+
<artifactId>spring-aop-03-AfterReturning</artifactId>
12+
<description>Spring AOP - @AfterReturning aspect example</description>
1313

1414
<dependencies>
1515
<dependency>

spring-aop-04-@AfterThrowing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
11-
<artifactId>spring-aop-04-@AfterThrowing</artifactId>
11+
<artifactId>spring-aop-04-AfterThrowing</artifactId>
1212
<description>Spring AOP - @AfterThrowing advice example</description>
1313

1414
<dependencies>

spring-aop-04-@AfterThrowing/src/main/java/c/jbd/saop/at/aspect/ExceptionAspect.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import org.aspectj.lang.JoinPoint;
44
import org.aspectj.lang.annotation.AfterThrowing;
55
import org.aspectj.lang.annotation.Aspect;
6-
import org.springframework.stereotype.Service;
6+
import org.springframework.context.annotation.Configuration;
77

8-
@Service
8+
@Configuration
99
@Aspect
1010
public class ExceptionAspect {
1111

1212
/**
13-
*
13+
* Match with all dao methods.
14+
*
1415
* @param joinPoint
1516
* @param exception
1617
*/

spring-aop-04-@AfterThrowing/src/test/java/c/jbd/saop/at/TestAfterThrowing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public void notNull() {
1919

2020
@Test
2121
public void testThrows() {
22-
//Assert exception
22+
//Assert throws RuntimeException
2323
Assertions.assertThrows(RuntimeException.class, () -> {
2424
userRepository.add(null);
2525
userRepository.delete(null);
2626
});
2727

28-
//Assert exception
28+
//Assert does not throw exception
2929
Assertions.assertDoesNotThrow(() -> {
3030
userRepository.delete("alexa");
3131
});

spring-aop-05-@After/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
11-
<artifactId>spring-aop-05-@After</artifactId>
11+
<artifactId>spring-aop-05-After</artifactId>
1212
<description>Spring AOP - @After advice example</description>
1313

1414
<dependencies>

spring-aop-05-@After/src/test/java/com/jbd/saop/after/TestAfter.java renamed to spring-aop-05-@After/src/test/java/com/jbd/saop/after/TestAfterAdvice.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
88

99
@SpringJUnitConfig(ApplicationConfig.class)
10-
public class TestAfter{
10+
public class TestAfterAdvice {
1111

1212
@Autowired
1313
private UserRepository userRepository;
@@ -30,8 +30,5 @@ public void testThrows() {
3030
userRepository.delete("alexa");
3131
});
3232
}
33-
34-
@Test
35-
public void testAfter(){}
3633

3734
}

spring-aop-06-@Around/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
11-
<artifactId>spring-aop-06-@Around</artifactId>
11+
<artifactId>spring-aop-06-Around</artifactId>
1212
<description>Spring AOP - @Around aspect example</description>
1313

1414
<dependencies>

0 commit comments

Comments
 (0)