我发现了错误原因,仅当我手动定义时才会发生
PersistenceAnnotationBeanPostProcessor:
@Bean public PersistenceAnnotationBeanPostProcessor persistenceAnnotationBeanPostProcessor() {// enable injection of EntityManager to beans with @PersistenceContext annotationreturn new PersistenceAnnotationBeanPostProcessor(); }很抱歉,因为我没有在问题中发布完整的代码(因为我认为这个bean没关系)。当我删除此定义时,一切都会按预期进行。我还发现在我的情况下该bean已经被注册:
注意:默认的PersistenceAnnotationBeanPostProcessor将通过“ context:annotation-
config”和“ context:component-scan”
XML标签进行注册。如果要指定自定义PersistenceAnnotationBeanPostProcessor
bean定义,请删除或关闭那里的默认注释配置。
(来自的引用评论
org.springframework.orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java)



