1

I have a Spring Rest Application built using Spring Boot framework. Now while writing Spring Integration Test, I wanted to exclude a class from being get component scanned.my this class contains the dependency for Apache Kafka. if this class loads while container start up it start looking for Kafka running instances.

so while running Integration test I will not be starting my Kafka server,so I wanted to run Integration test making Kafka shutdown.

any help is appreciated.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Shobhit Pal
  • 83
  • 1
  • 1
  • 8
  • you can specify configuration for test separately, mocking services or testing your app by slices : https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4 – Sergii Getman Feb 15 '17 at 07:50

2 Answers2

1

You can exclude the cafka configuration from your test configuration. You haven't shared your code but it would be something like this

@SpringBootApplication(exclude = CafkaConfiguration.class)
public class IntegrationTestConfig { 
}

On the other thought you can sure mock the kafka

How can I instanciate a Mock Kafka Topic for junit tests?

Community
  • 1
  • 1
mirmdasif
  • 6,014
  • 2
  • 22
  • 28
  • can you pls refer this link .. I re asked this question providing more information. http://stackoverflow.com/questions/42245236/exclude-a-particular-class-from-spring-component-scan-while-writing-spring-integ – Shobhit Pal Feb 15 '17 at 09:24
0

The easiest way to do this is to use profiles. In the bean that you only want to be visible to the intergration test add :

@Profile("integration=test")

At the top of the integration test, activate the profile:

@ActiveProfile("integration-test")

Any beans which do not specify a profile (all the other beans) will be present in both test and default profiles. Default is the name of the profile if none is given.

Essex Boy
  • 7,565
  • 2
  • 21
  • 24
  • http://stackoverflow.com/questions/42245236/exclude-a-particular-class-from-spring-component-scan-while-writing-spring-integ – Shobhit Pal Feb 15 '17 at 09:24