Requested bean is currently in creation: Is there an unresolvable circular reference?
Spring bootを2.5.12にバージョンアップしたら「Requested bean is currently in creation: Is there an unresolvable circular reference?」エラーが発生しました。
bitronixを使用して複数データベースに接続していたのですが、その箇所でエラーとなっていたので修正しました。DBはPostgreSQLです。
package com.example.demo.config;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import bitronix.tm.resource.jdbc.PoolingDataSource;
@Configuration
@DependsOn("transactionManager")
@EnableJpaRepositories(entityManagerFactoryRef = "db1EntityManagerFactory", transactionManagerRef = "transactionManager", basePackages = "com.example.demo.repository.primary")
public class PrimaryDbConfig {
@Autowired private MyDataSource1 dataSource;
// @Autowired private JpaVendorAdapter jpaVendorAdapter; // コメントアウト
@Primary
@Bean(name = "db1DataSource")
public DataSource dataSource() {
final PoolingDataSource xaDataSource = dataSource.getXAPrimaryDataSource();
xaDataSource.setUniqueName("db1DataSource");
return xaDataSource;
}
@Primary
@Bean(name = "db1EntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
@Qualifier("db1DataSource") DataSource dataSource) {
final Map<String, Object> properties = new HashMap<>();
properties.put("hibernate.transaction.jta.platform", BJtaPlatform.class.getName());
properties.put("javax.persistence.transactionType", "JTA");
properties.put("hibernate.jdbc.lob.non_contextual_creation", true);
properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL10Dialect"); // 追加
final LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
entityManager.setJtaDataSource(dataSource);
final JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); // 追加
entityManager.setJpaVendorAdapter(jpaVendorAdapter); // 追加
entityManager.setPackagesToScan("com.example.demo.entity.primary");
entityManager.setPersistenceUnitName("PrimaryDataBase");
entityManager.setJpaPropertyMap(properties);
return entityManager;
}
}
Spring bootのバージョンアップって何気に面倒です。
「Spring Boot+JPA+bitronixで2相コミットを実装する方法」
Spring Boot 2.6 Release Notes
Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss. -...

How to set some Hibernate properties in Spring JPA Web Application?
I am trying to get rid of the typical persistence.xml file in Spring JPA web application. So far, I have managed to inje...

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^

コメント