gpt4 book ai didi

java - 如何将服务传递给 EmptyInterceptor 类?

转载 作者:行者123 更新时间:2023-12-01 04:53:24 25 4
gpt4 key购买 nike

public class Auditing extends EmptyInterceptor {

@Resource
private ApplicationService applicationService;

public boolean onFlushDirty(Object entity, Serializable id,Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
if(applicationService == null){
System.out.println("applicationService is null");
}

return(true);
}

}

我观察到,对于每个 hibernate 操作,都会创建一个新的审核对象,并且在 onFlushDirty() 中它始终打印“applicationService is null”

谁能告诉我如何使 ApplicationService 在 EmptyInterceptor 中可用?

最佳答案

我通过使用具有静态 applicationService 属性的类找到了解决此问题的方法。现在,通过为其创建静态引用,我可以使用 applicationService。

目前可以使用。如果您有任何更好或有效的建议,请发布:)

问候,

关于java - 如何将服务传递给 EmptyInterceptor 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14577521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com