Updated
My class listed below (ServiceDiscoveryConfiguration
) is never being utilized. Even if I remove the @EnableDiscoveryClient
to attempt to completely avoid the setup, it still attempts to connect to Consul.
The only thing that worked for me was removing the Consul Maven depdency completely:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
What can I do to prevent Consul for running for unit tests if not through the profile and annotation setup?
Original
I have an application using Spring Consul. I have a class set up to enable discovery like this:
@Profile ("!" + Profiles.UNIT_TEST)
@Configuration
@EnableDiscoveryClient
public class ServiceDiscoveryConfiguration {
}
This should be disabling the Consul portion, if I am not mistaken. The base test class (it's an abstract
shared between all of my unit tests) is setup up with the following annotations. This is where I think the problem is.
@SpringBootTest (classes = Service.class)
@WebAppConfiguration
@TestExecutionListeners (...)
@DirtiesContext
@ActiveProfiles (Profiles.UNIT_TEST)
@Test (...)
public abstract class AbstractBootTest extends AbstractTestNGSpringContextTests {
// ...
}
When I execute my tests I get:
Caused by: com.ecwid.consul.transport.TransportException: java.net.ConnectException: Connection refused
This leads me to believe that the profile activation is not working or my syntax using the !
operator on the @Profile
specification is not doing what I thought it was supposed to be doing. The root execution class itself has basic annotations including a @ComponentScan
annotation that I know has the appropriate packages being scanned.
Assistance?