I´d like to override the PersistenceAnnotationBeanPostProcessor which gets registered as soon as I insert a context:component-scan tag.
I tried to register a bean with the same name, but spring still registers the original postprocessor bean.
My goal is to provide an overriden version of findDefaultEntityManager method which will alow me to declare two EntityManagers in the same container.
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.
Why not using the
unitName
attribute of your@PersistenceUnit
/@PersistenceContext
annotations? Since the javaDoc of PersistenceAnnotationBeanPostProcessor says it is supported...I found this workaround has worked for me ( Spring 3.2.7):
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.