How do I expose entity ids in a mutiple datasource project?

Viewed 41

My project talks to at least two databases with the requirement that entity ids be exposed. I've tried most solutions online but kept getting this error: Field manager in ... required a single bean, but 2 were found:... How do I achieve this requirement using this simplified config class?

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages={...}
public class MyConfig{
@Autowired
private EntityManager manager;
@Bean
@Primary
@ConfigurationProperties("spring.datasource.akad")
public DataSourceProperties akadDataSourceProps(){
return new DataSourceProperties();
}

@Primary
@Bean
@ConfigurationProperties("spring.datasource.akad")
public DataSource akaData(){
return akadDataSourceProps().initialzeDataSourceBuilder.type(HikariDataSource.class).build();
}

@Primary
@Bean(name = "akadEntityFac")
public LocalEntityManagerFactoryBean akaFact(EntityManagerFactoryBuilder build){

String [] packgesToScan = {...};

return builder.datasource(akad()).packagesToScan).build();
}

@Primary
@Bean
public PlatformTransactionManager akadMan("akadEntityFac") LocalEntityManagerFactoryBean akadManFac){

return JpaTransactionManager(akadManFac.getObject());

//this method below throws the error
@Primary
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors){
config.exposeIdsFor(manager.getMetaModel().getEntities().stream().map(Type::getJavaType).toArray(Class[]::new));
}

//If I comment the last method, the error would be cleared but the entity ids wouldn't get exposed.
}


0 Answers
Related