File tree 8 files changed +114
-19
lines changed
kotlin/com/example/kotlin
8 files changed +114
-19
lines changed Original file line number Diff line number Diff line change 12
12
13
13
@ Aspect
14
14
@ Component
15
- public class TestAspect {
15
+ public class SimpleAspect {
16
16
17
- private static final Logger logger = LoggerFactory .getLogger (TestAspect .class );
17
+ private static final Logger logger = LoggerFactory .getLogger (SimpleAspect .class );
18
18
19
19
@ Before ("execution(* com.example.java.service.*.*Aop(..))" )
20
20
public void onBeforeHandler (JoinPoint joinPoint ) {
Original file line number Diff line number Diff line change 7
7
@ Service
8
8
public class TestServiceImpl implements TestService {
9
9
10
- private static final Logger logger = LoggerFactory .getLogger (TestServiceImpl .class );
10
+ private static final Logger logger = LoggerFactory .getLogger (TestServiceImpl .class );
11
11
12
- @ Override
13
- public String test () {
14
- String msg = "Hello, Spring Boot No AOP" ;
15
- logger .info (msg );
16
- return msg ;
17
- }
12
+ @ Override
13
+ public String test () {
14
+ String msg = "Hello, Spring Boot No AOP" ;
15
+ logger .info (msg );
16
+ return msg ;
17
+ }
18
18
19
- @ Override
20
- public String testAop () {
21
- String msg = "Hello, Spring Boot AOP" ;
22
- logger .info (msg );
23
- return msg ;
24
- }
19
+ @ Override
20
+ public String testAop () {
21
+ String msg = "Hello, Spring Boot AOP" ;
22
+ logger .info (msg );
23
+ return msg ;
24
+ }
25
25
}
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
4
4
import org.springframework.boot.runApplication
5
5
6
6
@SpringBootApplication
7
- class SpringBootAopApplication {
8
- fun main ( args : Array < String >) {
9
- runApplication< SpringBootAopApplication >( * args)
10
- }
7
+ class SpringBootAopApplication
8
+
9
+ fun main ( args : Array < String >) {
10
+ runApplication< SpringBootAopApplication >( * args)
11
11
}
12
12
Original file line number Diff line number Diff line change
1
+ package com.example.kotlin.component
2
+
3
+ import org.aspectj.lang.JoinPoint
4
+ import org.aspectj.lang.annotation.*
5
+ import org.slf4j.Logger
6
+ import org.slf4j.LoggerFactory
7
+ import org.springframework.stereotype.Component
8
+
9
+ @Aspect
10
+ @Component
11
+ class SimpleAspect {
12
+
13
+ private val logger = LoggerFactory .getLogger(SimpleAspect ::class .java)
14
+
15
+ @Before(" execution(* com.example.kotlin.service.*.*Aop(..))" )
16
+ fun onBeforeHandler (joinPoint : JoinPoint ) {
17
+ logger.info(" =============== onBeforeThing" )
18
+ }
19
+
20
+ @After(" execution(* com.example.kotlin.service.*.*Aop(..))" )
21
+ fun onAfterHandler (joinPoint : JoinPoint ) {
22
+ logger.info(" =============== onAfterHandler" )
23
+ }
24
+
25
+ @AfterReturning(pointcut = " execution(* com.example.kotlin.service.*.*Aop(..))" , returning = " str" )
26
+ fun onAfterReturningHandler (joinPoint : JoinPoint , str : Any ) {
27
+ logger.info(" @AfterReturning : $str " )
28
+ logger.info(" =============== onAfterReturningHandler" )
29
+ }
30
+
31
+ @Pointcut(" execution(* com.example.kotlin.service.*.*Aop(..))" )
32
+ fun onPointcut (joinPoint : JoinPoint ) {
33
+ logger.info(" =============== onPointcut" )
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ package com.example.kotlin.config
2
+
3
+ import org.springframework.context.annotation.Configuration
4
+ import org.springframework.context.annotation.EnableAspectJAutoProxy
5
+
6
+ @Configuration
7
+ @EnableAspectJAutoProxy
8
+ class AspectJConfig
Original file line number Diff line number Diff line change
1
+ package com.example.kotlin.service
2
+
3
+ interface TestService {
4
+
5
+ fun testAop (): String
6
+ fun test (): String
7
+ }
Original file line number Diff line number Diff line change
1
+ package com.example.kotlin.service
2
+
3
+ import org.slf4j.LoggerFactory
4
+ import org.springframework.stereotype.Service
5
+
6
+ @Service
7
+ class TestServiceImpl : TestService {
8
+
9
+ private val logger = LoggerFactory .getLogger(TestServiceImpl ::class .java)
10
+
11
+ override fun test (): String {
12
+ val msg = " Hello, Spring Boot With Kotlin No AOP"
13
+ logger.info(msg)
14
+ return msg
15
+ }
16
+
17
+ override fun testAop (): String {
18
+ val msg = " Hello, Spring Boot With Kotlin AOP"
19
+ logger.info(msg)
20
+ return msg
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ package com.example.kotlin.web
2
+
3
+ import com.example.kotlin.service.TestService
4
+ import org.springframework.beans.factory.annotation.Autowired
5
+ import org.springframework.web.bind.annotation.GetMapping
6
+ import org.springframework.web.bind.annotation.RestController
7
+
8
+ @RestController
9
+ class TestController {
10
+
11
+ @Autowired
12
+ private lateinit var service: TestService
13
+
14
+ @GetMapping(value = [" /noAop" ])
15
+ fun noAop (): String {
16
+ return service.test()
17
+ }
18
+
19
+ @GetMapping(value = [" /aop" ])
20
+ fun aop (): String {
21
+ return service.testAop()
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments