package com.thhy.general.config.mysql; import com.thhy.general.annotations.Idkey; import com.thhy.general.common.enums.DataSources; import com.thhy.general.utils.UUIDUtils; import org.apache.ibatis.session.SqlSessionFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @Component @Aspect @ConditionalOnProperty(prefix = "spring.datasource.hikari",value = "minIdle",havingValue = "10") public class TransacationAop { @Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)") public void pointcut(){ } /*@Autowired private DataSourceTransactionManager transactionManager;*/ @Autowired private SqlSessionFactory sessionFactory; @Around("pointcut()") public Object invoke(ProceedingJoinPoint invocation) throws Throwable { DynamicDataSource.setDataSource(DataSources.MASTER.name()); return invocation.proceed(); } }