简体   繁体   中英

How can I avoid Spring Boot from loading EmbeddedWebApplicationContext?

I have an Spring Boot integration application with Camel-HTTP. Since Camel-HTTP has a dependency to geronimo-servlet Spring Boot is trying to load the web application context.

How can I force Spring to not load the EmbeddedWebApplicationContext ?

I have tried to exclude all the AutoConfiguration classes found in org.springframework.boot.autoconfigure.web with the @EnableAutoConfiguration(exclude = ...) annotation.

You can use the SpringApplicationBuilder class to explicitly disable loading a web environment and context, ie in your main class:

public static void main(String[] args) {
    new SpringApplicationBuilder(MainConfig.class).web(false).run(args);
}

You can try using the @ContextConfiguration annotation:

@ContextConfiguration(loader = SpringApplicationCtxtLoader.class, classes = annotatedClass.class)

The annotatedClass.class are the class that are annotated , for instance with: @Component , @Service , @Repository .

In this answer this is the suggested approach for testing purposes, but I think it might help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM