springboot - op 절단면 설정 전역 사무
4878 단어 자바springboot
package com.platform.generator.aspect;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
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.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.interceptor.*;
@Slf4j
@Aspect
@Configuration
public class TxAdviceInterceptor {
private static final String AOP_POINTCUT_EXPRESSION = "execution(* com.platform.service.impl.*.*(..))";
/**
*
*/
// private static final String AOP_POINTCUT_EXPRESSION = "execution(* com.platform.service.impl.*.*(..))" +
// " || execution(* com.platform.generator.aspect.*.*(..))";
private static final int TX_METHOD_TIMEOUT = 5000;
@Autowired
private DataSourceTransactionManager transactionManager;
@Bean
public TransactionInterceptor txAdvice() {
/* , **/
NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
/* , */
RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
readOnlyTx.setReadOnly(true);
/* transactiondefinition PROPAGATION_NOT_SUPPORTED 5, , , */
readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
/* , */
RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute();
/* **/
requiredTx.setRollbackRules(Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
/*PROPAGATION_REQUIRED: 1, , ; , 。 。 */
requiredTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
/* , 5 , */
requiredTx.setTimeout(TX_METHOD_TIMEOUT);
Map txMap = new HashMap<>();
txMap.put("save*", requiredTx);
txMap.put("remove*", requiredTx);
txMap.put("update*", requiredTx);
txMap.put("batch*", requiredTx);
txMap.put("clear*", requiredTx);
txMap.put("add*", requiredTx);
txMap.put("append*", requiredTx);
txMap.put("modify*", requiredTx);
txMap.put("edit*", requiredTx);
txMap.put("insert*", requiredTx);
txMap.put("delete*", requiredTx);
txMap.put("do*", requiredTx);
txMap.put("create*", requiredTx);
/*select,count , , */
txMap.put("select*", readOnlyTx);
txMap.put("get*", readOnlyTx);
txMap.put("valid*", readOnlyTx);
txMap.put("list*", readOnlyTx);
txMap.put("count*", readOnlyTx);
txMap.put("find*", readOnlyTx);
txMap.put("load*", readOnlyTx);
txMap.put("search*", readOnlyTx);
txMap.put("*", requiredTx);
source.setNameMap(txMap);
TransactionInterceptor txAdvice = new TransactionInterceptor(transactionManager, source);
return txAdvice;
}
@Bean
public Advisor txAdviceAdvisor() {
/* : 。 —— 、 * */
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
/* , **/
pointcut.setExpression(AOP_POINTCUT_EXPRESSION);
/* = pointcut+ TxAdvice**/
return new DefaultPointcutAdvisor(pointcut, txAdvice());
}
/**
@Pointcut("execution(* com.platform.service.impl.*.*(..))")
public void logPointCut() {
}
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
//long beginTime = System.currentTimeMillis();
//
// Object result = point.proceed();
// ( )
// long time = System.currentTimeMillis() - beginTime;
//
log.info(" @Around*******************"+" dong "+"********************** @Around");
return "";
}
**/
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.