title: Exclude a particular class from Spring Component scan while writing Spring Integration Test
body: <p>My classes are..</p>
  
  <p>lies in src/intregation-test/java</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = StoreOrderFulfillmentApplication.class)
    @ActiveProfiles("Test")
    public class OrderCreationIntregationTest {
  
  @Autowired
  private TestRestTemplate restTemplate;
  
  @MockBean
  private OrderRepository orderRepository;
  
  @MockBean
  private OrderLineItemRepository orderLineItemRepository;
  
  @MockBean
  private InternalEventPublisher internalEventPublisher;
  
  @SuppressWarnings("unchecked")
  @Before
  public void setup() {
      Mockito.when(orderRepository.findByOfsReferenceId("OFS:GMO:Z100002062-99")).thenReturn(null);
      OrderEntity savedOrder = new OrderEntity();
      savedOrder.setOrderId(1023);
      Mockito.when(orderRepository.save(Mockito.any(OrderEntity.class))).thenReturn(savedOrder);
      Iterable&lt;OrderLineItemEntity&gt; orderLineItemList = prepareOrderLineItemEntityIterable();
      Mockito.when(orderLineItemRepository.save(Mockito.any(Iterable.class))).thenReturn(orderLineItemList);
  }
  
  @Test
  public void test() throws ParseException {
      FulfillmentOrder fulfillmentOrderRequestVO = new FulfillmentOrder();
      fulfillmentOrderRequestVO = buildFulfillmentOrder();
      String myMessage = "Order Created";
      ResponseEntity&lt;ResponseOrderMessage&gt; responseEntity = restTemplate.postForEntity("/fulfillmentprocessor/orders",
              fulfillmentOrderRequestVO, ResponseOrderMessage.class);
      ResponseOrderMessage responseOrderMessage = responseEntity.getBody();
      assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
      assertEquals(myMessage, responseOrderMessage.getMessage());
  }
  </code></pre>
  
  <p>lies in src/main/java</p>
  
  <pre><code>@SpringBootApplication
  public class StoreOrderFulfillmentApplication {
  
  public static void main(String[] args) {
      SpringApplication.run(StoreOrderFulfillmentApplication.class, args);
  }
  }
  </code></pre>
  
  <p>Now the problem is 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 Intregation test I will not be starting my Kafka server,so I wanted to run
  Intregation test making kafka shutdown.</p>
  
  <p>This I can achieved by adding one line code in  StoreOrderFulfillmentApplication class</p>
  
  <pre><code>@ComponentScan(basePackages = "com.tesco.store.order.fulfillment.processor", excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = OrderReceiveEventConfiguration.class))
  </code></pre>
  
  <p>by addding this line of code StoreOrderFulfillmentApplication class it is excluding OrderReceiveEventConfiguration class from being get component scanned.</p>
  
  <p>now the problem is I not suppose add any test configuration changes in the main code.
  so I am struggling to do the same exclusion from <b>src/intregation-test/java</b> source folder, is their some way that I can exclude this particular class during container startup code.</p>
  
  <p>but it should not affect my main class code means code inside <b>src/main/java</b></p>
  
  <p>Any help is Appreciated.. </p>