cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Reactive + Spring Boot + Neo4j + SDN Multiple DB - Unable to detect customized driver configuration

We are trying to configure two different neo4j db instance of same URI in reactive spring boot application. We have configured two different configuration as well. One of the configuration mentioned below but it's not detecting the configuration rather it's only considered what database mentioned in application.yml file i.e. spring.data.neo4j.database. If we don't mentioned this in yml file then it's inserting into default neo4j db. Although we have hardcoded the db in configuration file but it's not picking that.

application.yml


spring:
  application:
  neo4j:
    repositories:
      type: reactive
    uri: bolt://localhost:11003/
    authentication:
      password: Test
      username: neo4j
  data:
    neo4j:
      database: ocean

inland:
  spring:
    neo4j:
      repositories:
        type: reactive
      uri: bolt://localhost:11003/
      authentication:
        password: Test
        username: neo4j
    data:
      neo4j:
        database: oceans

@Configuration(proxyBeanMethods = false)
@EnableReactiveNeo4jRepositories(
        basePackageClasses = InlandNeo4jConfiguration.class,
        neo4jMappingContextRef = "inlandContext",
        transactionManagerRef = "inlandManager")

@Slf4j
public class InlandNeo4jConfiguration {

    @Bean
    public Driver inlandDriver(@Qualifier("inlandProperties") Neo4jProperties inlandProperties) {
        var authentication = inlandProperties.getAuthentication();
        return GraphDatabase.driver(inlandProperties.getUri(), AuthTokens.basic(
                authentication.getUsername(), authentication
                        .getPassword()),
                Config.builder()
                        .withMaxConnectionLifetime(3, TimeUnit.MINUTES)
                        .build());
    }

    @Bean
    public ReactiveDatabaseSelectionProvider inlandSelection(
            @Qualifier("inlandDataProperties") Neo4jDataProperties inlandDataProperties) {
        log.info("Inland db {}", inlandDataProperties.getDatabase());
        return () -> Mono.just(DatabaseSelection.byName("inlandsurcharge"));
    }

    @Bean
    public ReactiveTransactionManager inlandManager(
            @Qualifier("inlandDriver") Driver driver,
            @Qualifier("inlandSelection") ReactiveDatabaseSelectionProvider inlandSelection) {
        return new ReactiveNeo4jTransactionManager(driver, inlandSelection);
    }

    @Bean
    public Neo4jMappingContext inlandContext(ResourceLoader resourceLoader, Neo4jConversions neo4jConversions)
            throws ClassNotFoundException {
        Neo4jMappingContext context = new Neo4jMappingContext(neo4jConversions);
        context.setInitialEntitySet(Neo4jEntityScanner.get(resourceLoader).scan(this.getClass().getPackageName()));
        return context;
    }

@Configuration(proxyBeanMethods = false)
@EnableReactiveNeo4jRepositories(
        basePackageClasses = OceanNeo4jConfiguration.class,
        neo4jMappingContextRef = "oceanContext",
        transactionManagerRef = "oceanManager")

@Slf4j
public class OceanNeo4jConfiguration {

    @Bean
    @Primary
    public Driver oceanDriver(Neo4jProperties oceanProperties) {
        var authentication = oceanProperties.getAuthentication();
        return GraphDatabase.driver(oceanProperties.getUri(), AuthTokens.basic(
                authentication.getUsername(), authentication
                        .getPassword()),
                Config.builder()
                        .withMaxConnectionLifetime(3, TimeUnit.MINUTES)
                        .build());
    }

    @Bean
    @Primary
    public ReactiveTransactionManager oceanManager(
            Driver driver,
            ReactiveDatabaseSelectionProvider oceanSelection) {
        return new ReactiveNeo4jTransactionManager(driver, oceanSelection);
    }

    @Bean
    @Primary
    public ReactiveDatabaseSelectionProvider oceanSelection(
            Neo4jDataProperties oceanDataProperties) {
        return () -> Mono.just(DatabaseSelection.byName("ocean"));
    }

    @Bean
    @Primary
    public Neo4jMappingContext oceanContext(ResourceLoader resourceLoader, Neo4jConversions neo4jConversions)
            throws ClassNotFoundException {
        Neo4jMappingContext context = new Neo4jMappingContext(neo4jConversions);
        context.setInitialEntitySet(Neo4jEntityScanner.get(resourceLoader).scan(this.getClass().getPackageName()));
        return context;
    }

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online