Spring Data JPA Pointcut格式错误:在eclipse中Class不能为空警告

时间:2018-02-15 05:51:01

标签: java spring spring-aop

我正在使用SPring Data JPA。我创建了一个AOP Aspect来在数据库之间切换,比如当需要读连接时交换到副本,当需要写连接时交换到Master。但Eclipse显示警告 Pointcut格式错误:Class不能为null。

package com.casa.core.sqljpa.annotation;

import org.apache.log4j.Logger;
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.Value;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import com.casa.core.sqljpa.DbContextHolder;
import com.casa.core.sqljpa.enums.DbType;

@Aspect
@Component
public class WriteConnectionInterceptor implements Ordered {

    private static final Logger logger = Logger.getLogger(WriteConnectionInterceptor.class);

    private int order;

    @Value("20")
    public void setOrder(int order) {
        this.order = order;
    }

    @Override
    public int getOrder() {
        return order;
    }

    @Pointcut(value = "execution(public * *(..))")
    public void anyPublicMethod() {
    }

    @Around("@annotation(writeConnection)")
    public Object proceed(ProceedingJoinPoint pjp, WriteConnection writeConnection) throws Throwable {
        try {
            logger.debug(Thread.currentThread().getName() + ": In Write Only Connection");
            DbContextHolder.setDbType(DbType.MASTER);
            Object result = pjp.proceed();
            DbContextHolder.clearDbType();

            return result;
        } finally {
            // restore state
            DbContextHolder.clearDbType();
        }
    }
}

请帮助解决问题。

0 个答案:

没有答案