@Aspect 类获取 null EntityManagerFactory
我已经声明了如下所示的方面
@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;
}
}
现在正在调用方面方法,但我得到的是 null EntityManagerFactory。请指出我这样做的正确性! 提前致谢。
I have declared an aspect 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论