【发布时间】:2011-05-09 21:01:36
【问题描述】:
我有以下类(它是一个 JPA 实体监听器):
@Service
public class AuditLogListener {
@Autowired
IDomainObjectDAO domainObjectDAO;
@PostLoad
public void saveOldData(DomainObject obj) {
domainObjectDAO.findAll();
System.out.println("after Load");
}
@PreUpdate
public void logChanges(DomainObject obj) {
}
}
domainObjectDAO 被 Spring 识别并根据日志自动连接。
日志摘录:
[http-8080-1] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Found injected element on class [com.legolas.entityListeners.AuditLogListener]: AutowiredFieldElement for com.legolas.dao.interfaces.IDomainObjectDAO com.legolas.entityListeners.AuditLogListener.domainObjectDAO
[http-8080-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'auditLogListener' to allow for resolving potential circular references
[http-8080-1] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'auditLogListener': AutowiredFieldElement for com.legolas.dao.interfaces.IDomainObjectDAO com.legolas.entityListeners.AuditLogListener.domainObjectDAO
[http-8080-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'domainObjectDAO'
[http-8080-1] DEBUG org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - Autowiring by type from bean name 'auditLogListener' to bean named 'domainObjectDAO'
但是在调试模式下检查字段时,我看到字段为空,并且在调用findAll() 方法时抛出异常。
为什么归档为空,有没有办法解决这个问题?
谢谢。
【问题讨论】: