by Anonymous » 25 Aug 2025, 12:48
Ich versuche, 2 Datenbanken in einer einzelnen Spring -Boot -Anwendung zu konfigurieren. Damit ich 2 separate Konfigurationsdateien für Postgres und Postgres Vector DB konfiguriert habe. < /P>
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.
Wie kann ich dieses
Problem lösen?
Ich versuche, 2 Datenbanken in einer einzelnen Spring -Boot -Anwendung zu konfigurieren. Damit ich 2 separate Konfigurationsdateien für Postgres und Postgres Vector DB konfiguriert habe. < /P>
[code]@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.
[/code]
Wie kann ich dieses [url=viewtopic.php?t=26065]Problem[/url] lösen?