Code: Select all
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
basePackages = "com.example.sse_chat_bot.repository.primary",
entityManagerFactoryRef = "primaryEntityManagerFactory",
transactionManagerRef = "primaryTransactionManager"
)
public class PrimaryDataSourceConfig {
@Bean(name = "primaryDataSourceProperties")
@ConfigurationProperties("spring.datasource.primary")
public DataSourceProperties dataSourceProperties() {
return new DataSourceProperties();
}
@Bean(name = "primaryDataSource")
public DataSource dataSource() {
return dataSourceProperties().initializeDataSourceBuilder().build();
}
// The streamlined, modern approach - no separate builder bean needed
@Bean(name = "primaryEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("primaryDataSource") DataSource dataSource
) {
return builder
.dataSource(dataSource) // Set the DataSource
.packages("com.example.sse_chat_bot.entity.primary")
.build();
}
@Bean(name = "primaryTransactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("primaryEntityManagerFactory") LocalContainerEntityManagerFactoryBean entityManagerFactory
) {
return new JpaTransactionManager(entityManagerFactory.getObject());
}
}
< /code>
Aber der Fehler < /p>
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method entityManagerFactory in com.example.sse_chat_bot.config.PrimaryDataSourceConfig required a bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' in your configuration.
Spring is unable to autowire the EntityManagerFactoryBuilder.