24 Ekim 2018 Çarşamba

SpringData PersistenceAnnotationBeanPostProcessor Sınıfı

Giriş
Şu satırı dahil ederiz.
import org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor;
Açıklaması şöyle. Normalde bu bean'i yaratmaya gerek yok.
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor is automatically loaded into App Context by Spring when using annotation based configuration. One of its duties is to search the proper entity EntityManagerFactory that would provide the EntityManager for you @PersistenceContext annotated properties.

If you have multiple EntityManagerFactory beans in you spring config/context and you have @PersistenceContext annotations without a unitName attribute (lets say you are using a framework that comes with such a bean, and you can't touch framework code), you may run into this exception:  org.springframework.beans.factory.NoUniqueBeanDefinitionException.
constructor
Şöyle yaparız.
@Bean
public PersistenceAnnotationBeanPostProcessor persistenceAnnotationBeanPostProcessor() {
  return new PersistenceAnnotationBeanPostProcessor();
}
defaultPersistenceUnitName Alanı
Şöyle yaparız.
<bean id="org.springframework.context.annotation.internalPersistenceAnnotationProcessor"
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" >
<property name="defaultPersistenceUnitName" value="entityManagerFactory"/>
</bean> 

Hiç yorum yok:

Yorum Gönder