Springboot Transaction Solution

1、引入springboot-aop start

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

主要是Usage里面的动态Proxy

 <dependency>
     <groupId>org.aspectj</groupId>
     <artifactId>aspectjweaver</artifactId>
     <version>1.9.7</version>
     <scope>compile</scope>
 </dependency>

2、开启动态代理

@EnableAspectJAutoProxy(exposeProxy = true)
@EnableDiscoveryClient
@SpringBootApplication
public class FamilyBookingApplication {

    public static void main(String[] args) {
        SpringApplication.run(FamilyBookingApplication.class, args);
    }

}

@EnableAspectJAutoProxy(exposeProxy = true):

开启aspectj动态Proxy功能。以后所有的动态Proxy都是aspectj对象暴露Proxy对象。

3、本类互调用代理对象调用

@Service("userService")
public class UserServiceImpl implements userService {
    
    @Transactional
    public void a(){
        UserService userService = (UserService)AopContext.currentProxy();
        userService.b();
        userService.c();
    }

    @Transactional
    public void b(){

    }

    @Transactional
    public void c(){

    }
}