Skip to content

Commit 79b874b

Browse files
committed
logging aspect
1 parent 5022513 commit 79b874b

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

spring-boot-data-aggregator-example/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<groupId>org.springframework.boot</groupId>
2828
<artifactId>spring-boot-starter</artifactId>
2929
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-aop</artifactId>
33+
</dependency>
3034
<dependency>
3135
<groupId>org.springframework.boot</groupId>
3236
<artifactId>spring-boot-starter-test</artifactId>

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/ExampleApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @since 2019/6/1 0:13
1818
*/
1919

20-
@SpringBootApplication
20+
@SpringBootApplication(scanBasePackages = "io.github.lvyahui8.spring.example")
2121
@Slf4j
2222
public class ExampleApplication {
2323

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.lvyahui8.spring.example.aspect;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.aspectj.lang.ProceedingJoinPoint;
5+
import org.aspectj.lang.annotation.Around;
6+
import org.aspectj.lang.annotation.Aspect;
7+
import org.aspectj.lang.annotation.Pointcut;
8+
import org.springframework.stereotype.Component;
9+
10+
/**
11+
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
12+
* @since 2019/7/7 23:17
13+
*/
14+
@Aspect
15+
@Component
16+
@Slf4j
17+
public class AggregateQueryLoggingAspect {
18+
19+
public AggregateQueryLoggingAspect() {
20+
log.info("init aspect bean");
21+
}
22+
23+
@Pointcut("execution(* io.github.lvyahui8.spring.aggregate.service.impl.DataBeanAggregateQueryServiceImpl.*(..))")
24+
public void aggregateQuery() {}
25+
26+
@Around("execution(* io.github.lvyahui8.spring.aggregate.service.impl.DataBeanAggregateQueryServiceImpl.*(..))")
27+
public Object doLogging(ProceedingJoinPoint joinPoint) throws Throwable {
28+
Object retVal ;
29+
try {
30+
retVal = joinPoint.proceed();
31+
} finally {
32+
log.info("x");
33+
}
34+
return retVal;
35+
}
36+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
spring.main.banner-mode=off
22
io.github.lvyahui8.spring.base-packages=io.github.lvyahui8.spring.example
33
io.github.lvyahui8.spring.ignore-exception=false
4-
io.github.lvyahui8.spring.enable-logging=false
4+
io.github.lvyahui8.spring.enable-logging=false
5+
spring.aop.auto=true
6+
spring.aop.proxy-target-class=true

0 commit comments

Comments
 (0)