slorinc
slorinc

Reputation: 2496

Disable autoconfiguration for Spring Cloud Config in a test class of a Spring Boot application

I have a test class annotated with @DataJpaTest which autoconfigures Cloud Config.

I want to stop that for that one test class. I cannot use the spring.cloud.config.enabled=false application property, because that would disable it for all tests.

Any suggestions?

Upvotes: 2

Views: 2633

Answers (2)

pvpkiran
pvpkiran

Reputation: 27018

@DataJpaTest takes a excludeAutoConfiguration argument. You can specify all the AutoConfig's which you want to exclude.

@DataJpaTest(excludeAutoConfiguration = {AbcCloudAutoConfig.class, DefCloudAutoConfig.class})

replace AbcCloudAutoConfig, DefCloudAutoConfig with the classes you want to exclude

Upvotes: 1

user11632952
user11632952

Reputation: 11

@DataJpaTest annotation has other attributes. I tried the following to specifically disable the Spring Cloud Config and it worked for me locally:

@DataJpaTest(properties = {"spring.cloud.config.enabled=false"})

Upvotes: 1

Related Questions