开发者

@Aspect class getting null EntityManagerFactory

I have declared an as开发者_开发知识库pect like the following


@Aspect
public class CacheMonitorImpl {
    private final static Logger LOG = LoggerFactory
            .getLogger(CacheMonitorImpl.class);

    private final static NumberFormat NF = new DecimalFormat("0.0###");

    @Autowired
    private EntityManagerFactory entityManagerFactory;

    @Around("execution(* aop.web.teacher.service..*.*(..))")
    public Object log(ProceedingJoinPoint pjp) throws Throwable {

        LOG.info("$$ Test Property :: " + testprop);

        if (!LOG.isDebugEnabled()) {
            LOG.info("####### Logger is not debug enabled"
                    + entityManagerFactory);
            return pjp.proceed();
        }

        HibernateEntityManagerFactory hbmanagerfactory = (HibernateEntityManagerFactory) entityManagerFactory;
        SessionFactory sessionFactory = hbmanagerfactory.getSessionFactory();

        Statistics statistics = sessionFactory.getStatistics();
        statistics.setStatisticsEnabled(true);

        long hit0 = statistics.getQueryCacheHitCount();
        long miss0 = statistics.getSecondLevelCacheMissCount();

        Object result = pjp.proceed();

        long hit1 = statistics.getQueryCacheHitCount();
        long miss1 = statistics.getQueryCacheMissCount();

        double ratio = (double) hit1 / (hit1 + miss1);

        if (hit1 > hit0) {
            LOG.debug(String.format("CACHE HIT; Ratio=%s; Signature=%s#%s()",
                    NF.format(ratio), pjp.getTarget().getClass().getName(), pjp
                            .getSignature().toShortString()));
        } else if (miss1 > miss0) {
            LOG.debug(String.format("CACHE MISS; Ratio=%s; Signature=%s#%s()",
                    NF.format(ratio), pjp.getTarget().getClass().getName(), pjp
                            .getSignature().toShortString()));
        } else {
            LOG.debug("query cache not used");
        }

        return null;
    }

}

Now the aspect method is getting invoked but I am getting null EntityManagerFactory. Please point me to the correct of doing this! Thanks in advance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜