Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-10412

Unable to exclude CamelAutoConfiguration in Spring Boot

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.18.0
    • 2.19.0
    • camel-spring-boot
    • None
    • Unknown

    Description

      Prior to 2.18.0, you could exclude CamelAutoConfiguration in unit tests and no camel context would start up. This is useful for testing things in isolation that does not need camel and is a standard thing to do in Spring Boot since by default it auto configures everything it can find.

      Now with 2.18.0, there has been a lot more auto configuration classes added and required to be excluded. Virtually every *AutoConfiguration class found in camel-core-starter needs to be excluded. This is not practical to do.

      I have edited one file DirectComponentAutoConfiguration and added this line @ConditionalOnBean(CamelAutoConfiguration.class)

      and with my unit test, I can see it no longer tries to pull in that component.

      @RunWith(SpringJUnit4ClassRunner.class)
      @SpringBootTest
      public class PlainTest {
      
      	@Configuration
      	@EnableAutoConfiguration(exclude = { CamelAutoConfiguration.class
      
      			// , DirectComponentAutoConfiguration.class, DirectVmComponentAutoConfiguration.class,
      			// LogComponentAutoConfiguration.class, PropertiesComponentAutoConfiguration.class, RestComponentAutoConfiguration.class,
      			// SchedulerComponentAutoConfiguration.class, SedaComponentAutoConfiguration.class, StubComponentAutoConfiguration.class,
      			// ValidatorComponentAutoConfiguration.class, VmComponentAutoConfiguration.class, XsltComponentAutoConfiguration.class,
      			// GzipDataFormatAutoConfiguration.class, SerializationDataFormatAutoConfiguration.class, StringDataFormatAutoConfiguration.class,
      			// ZipDataFormatAutoConfiguration.class, BeanLanguageAutoConfiguration.class, ConstantLanguageAutoConfiguration.class,
      			// HeaderLanguageAutoConfiguration.class
      			//
      	})
      	public static class Config {
      
      	}
      
      	@Test
      	public void test() {
      		// do something
      	}
      }
      

      Unfortunately I cannot put this into git and commit since I see at the top of the DirectComponentAutoConfiguration file

      Generated by camel-package-maven-plugin - do not edit this file!
      

      I'm not sure what to edit to get this to auto generate correctly with the changes required so I'll leave it to you guys.

      Don't forget to update the camel-core-starter/pom.xml file and add the camel-spring-boot dependency in.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            mtran Minh Tran
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: