Chaks
Chaks

Reputation: 82

Spring Boot not picking up configuration from different application

I have a two spring applications DAO and Orchestrator. Ideally, I would want to keep my Cassandra Config inside DAO and inject that config inside Orchestrator. Which is what I am trying to do. But it always tries to pick up the spring.data.cassandra... config from application.properties and ignores the one in CassandraConfig.

I have tried multiple combinations inside my Application here but not able to figure this out. Even the copied Cassandra config to Orchestrator seems to run and then spring tries to override it with Default configuration. The DAO works fine independently and the Orchestrator works fine if I provide Cassandra properties like spring.data.cassandra....

Upvotes: 1

Views: 1022

Answers (2)

jccampanero
jccampanero

Reputation: 53411

Spring is picking up the default configuration for Cassandra as part of the auto-configuration process.

Please, try excluding CassandraDataAutoConfiguration from Spring Boot's auto-configuration. Your code will look like:

package com.uci.orchestrator.Application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableKafka
@EnableAsync
@ComponentScan(basePackages = {"com.uci.dao","com.uci.orchestrator", "messagerosa","com.uci.utils"})
@EnableReactiveCassandraRepositories("com.uci.dao")
@EntityScan(basePackages = {"com.uci.dao.models", "com.uci.orchestrator"})
@PropertySource("application-messagerosa.properties")
@PropertySource("application.properties")
@SpringBootApplication(exclude = { CassandraDataAutoConfiguration.class })
public class OrchestratorApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrchestratorApplication.class, args);
    }

}

I think you can safely remove the line:

@EnableReactiveCassandraRepositories("com.uci.dao")

as it is included in your dao CassandraConfig class:

@Configuration
@EnableReactiveCassandraRepositories(basePackages = "com.uci.dao")
public class CassandraConfig extends AbstractReactiveCassandraConfiguration {
  //...
}

Please, note that in addition I included com.uci.dao in your ComponentScan definition, it may be related with the problem as well:

@ComponentScan(basePackages = {"com.uci.dao","com.uci.orchestrator", "messagerosa","com.uci.utils"})

Upvotes: 1

luizinhoab
luizinhoab

Reputation: 475

You must disable the autoconfiguration to read @EnableReactiveCassandraRepositories(basePackages = "com.uci.dao"). You can do it:

Adding this property on application.properties:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration

or adding the exclude parameter on @SpringBootApplication in the main class:

@SpringBootApplication(exclude = CassandraDataAutoConfiguration.class)

Upvotes: 0

Related Questions