如何在Spring 3.0中注册自定义PersistenceAnnotationBeanPostProcessor [英] how to register custom PersistenceAnnotationBeanPostProcessor in spring 3.0

查看:98
本文介绍了如何在Spring 3.0中注册自定义PersistenceAnnotationBeanPostProcessor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写PersistenceAnnotationBeanPostProcessor,它会在我插入context:component-scan标记后立即注册.

I´d like to override the PersistenceAnnotationBeanPostProcessor which gets registered as soon as I insert a context:component-scan tag.

我试图注册一个具有相同名称的bean,但是spring仍然注册了原始的后处理器bean.

I tried to register a bean with the same name, but spring still registers the original postprocessor bean.

我的目标是提供findDefaultEntityManager方法的替代版本,使我能够在同一容器中声明两个EntityManager.

My goal is to provide an overriden version of findDefaultEntityManager method which will alow me to declare two EntityManagers in the same container.

注意:我在春季2.5.6上运行了2 EM上下文,但是当迁移到3.0.5.RELEASE版本时,它就坏了.

Note: I have the 2 EM context running on spring 2.5.6, but it gets broken when migrated to 3.0.5.RELEASE version.

推荐答案

我发现此解决方法对我有用(春季3.2.7):

I found this workaround has worked for me ( Spring 3.2.7):

<bean id="org.springframework.context.annotation.internalPersistenceAnnotationProcessor"
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" >
<property name="defaultPersistenceUnitName" value="entityManagerFactory"/>
</bean> 

这将用新的defaultPersistenceUnitName覆盖由Spring加载的默认PersistenceAnnotationBeanPostProcessor.您已经使用了自动加载该bean时使用的bean名称Spring(这是默认行为).我不得不研究org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors()来找出这个名字.

This would override the default PersistenceAnnotationBeanPostProcessor loaded by Spring with a new one with defaultPersistenceUnitName. You have to use the bean name Spring used when automatically loaded this bean (which is the default behaviour). I had to look into org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors() to figure out this name.

这篇关于如何在Spring 3.0中注册自定义PersistenceAnnotationBeanPostProcessor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆