File tree Expand file tree Collapse file tree
main/java/com/github/emeraldjava/springaop
test/java/com/github/emeraldjava/springaop Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 <name >spring-aop</name >
1515 <description >spring-aop</description >
1616 <properties >
17- <java .version>17 </java .version>
17+ <java .version>11 </java .version>
1818 </properties >
1919 <dependencies >
2020 <dependency >
2525 <groupId >org.springframework.boot</groupId >
2626 <artifactId >spring-boot-starter-aop</artifactId >
2727 </dependency >
28+ <!-- <dependency>-->
29+ <!-- <groupId>org.springframework</groupId>-->
30+ <!-- <artifactId>spring-aop</artifactId>-->
31+ <!-- </dependency>-->
32+ <!-- <dependency>-->
33+ <!-- <groupId>org.springframework</groupId>-->
34+ <!-- <artifactId>spring-aspects</artifactId>-->
35+ <!-- </dependency>-->
2836
2937 <dependency >
3038 <groupId >org.springframework.boot</groupId >
Original file line number Diff line number Diff line change 11# Spring AOP
22
33 https://reflectoring.io/aop-spring/
4+
5+ https://github.com/eugenp/tutorials/tree/master/spring-aop
6+
7+ https://www.baeldung.com/spring-aop
8+
9+ https://www.baeldung.com/spring-aop-vs-aspectj
10+
11+ https://jstobigdata.com/spring/pointcut-expressions-in-spring-aop/
12+
Original file line number Diff line number Diff line change 11package com .github .emeraldjava .springaop ;
22
33import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
45import org .springframework .boot .autoconfigure .SpringBootApplication ;
6+ import org .springframework .boot .autoconfigure .jdbc .DataSourceAutoConfiguration ;
7+ import org .springframework .boot .autoconfigure .jdbc .DataSourceTransactionManagerAutoConfiguration ;
8+ import org .springframework .boot .autoconfigure .orm .jpa .HibernateJpaAutoConfiguration ;
59
6- @ SpringBootApplication
10+ @ SpringBootApplication (exclude = {
11+ DataSourceAutoConfiguration .class ,
12+ DataSourceTransactionManagerAutoConfiguration .class ,
13+ HibernateJpaAutoConfiguration .class })
714public class SpringAopApplication {
815
916 public static void main (String [] args ) {
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .aspect ;
2+
3+
4+ import org .aspectj .lang .JoinPoint ;
5+ import org .aspectj .lang .annotation .Aspect ;
6+ import org .aspectj .lang .annotation .Before ;
7+ import org .aspectj .lang .annotation .Pointcut ;
8+ import org .springframework .stereotype .Component ;
9+
10+ @ Component
11+ @ Aspect
12+ public class LoggingAspect {
13+
14+ @ Pointcut ("execution(* com.github.emeraldjava.springaop.service.IBillNoArgs.createBill())" )
15+ public void logPointcutNoArgs () {}
16+
17+ @ Before ("logPointcutNoArgs()" )
18+ public void logMethodCallsWithArgsAdvice () {
19+ System .out .println ("In Aspect from logPointcutNoArgs" );
20+ }
21+ }
22+
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .aspect ;
2+
3+
4+ import org .aspectj .lang .JoinPoint ;
5+ import org .aspectj .lang .annotation .Aspect ;
6+ import org .aspectj .lang .annotation .Before ;
7+ import org .aspectj .lang .annotation .Pointcut ;
8+ import org .springframework .stereotype .Component ;
9+
10+ @ Component
11+ @ Aspect
12+ public class LoggingAspectWithArg {
13+
14+ @ Pointcut ("execution(* com.github.emeraldjava.springaop.service.IBillArgs.createBill(*))" )
15+ public void logPointcutArgs () {}
16+
17+ /**
18+ *
19+ * https://reflectoring.io/aop-spring/
20+ * @param joinPoint
21+ */
22+ @ Before ("logPointcutArgs()" )
23+ public void logMethodCallsWithArgsAdvice (JoinPoint joinPoint ) {
24+ System .out .println ("In Aspect from logPointcutArgs " +joinPoint .getSignature ().getName ());
25+ System .out .println ("arg " +joinPoint .getArgs ()[0 ]);
26+ }
27+ }
28+
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .aspect ;
2+
3+
4+ import org .aspectj .lang .JoinPoint ;
5+ import org .aspectj .lang .annotation .Aspect ;
6+ import org .aspectj .lang .annotation .Before ;
7+ import org .aspectj .lang .annotation .Pointcut ;
8+ import org .springframework .stereotype .Component ;
9+
10+ @ Component
11+ @ Aspect
12+ public class LoggingAspectWithArgException {
13+
14+ @ Pointcut ("execution(* com.github.emeraldjava.springaop.service.IBillArgsException.createBillEx(*))" )
15+ public void logPointcutArgsException () {}
16+
17+ @ Before ("logPointcutArgsException()" )
18+ public void logMethodCallsWithArgsAdvice (JoinPoint joinPoint ) {
19+ System .out .println ("In Aspect from logPointcutArgsException " +joinPoint .getSignature ().getName ());
20+ System .out .println ("arg " +joinPoint .getArgs ()[0 ]);
21+ }
22+ }
23+
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .config ;
2+
3+ import org .springframework .context .annotation .Configuration ;
4+ import org .springframework .context .annotation .EnableAspectJAutoProxy ;
5+
6+ /**
7+ *
8+ * See https://docs.spring.io/spring-framework/docs/4.3.15.RELEASE/spring-framework-reference/html/aop.html
9+ */
10+ @ Configuration
11+ @ EnableAspectJAutoProxy
12+ public class AspectConfig {
13+ }
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .service ;
2+
3+ public interface IBillArgs {
4+
5+ void createBill (Long id );
6+ }
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .service ;
2+
3+ public interface IBillArgsException {
4+
5+ void createBillEx (Long id ) throws Exception ;
6+ }
Original file line number Diff line number Diff line change 1+ package com .github .emeraldjava .springaop .service ;
2+
3+ public interface IBillNoArgs {
4+
5+ void createBill ();
6+ }
You can’t perform that action at this time.
0 commit comments