简体   繁体   English

如何避免Spring Boot加载EmbeddedWebApplicationContext?

[英]How can I avoid Spring Boot from loading EmbeddedWebApplicationContext?

I have an Spring Boot integration application with Camel-HTTP. 我有一个带Camel-HTTP的Spring Boot集成应用程序。 Since Camel-HTTP has a dependency to geronimo-servlet Spring Boot is trying to load the web application context. 由于Camel-HTTP依赖于geronimo-servlet Spring Boot正在尝试加载Web应用程序上下文。

How can I force Spring to not load the EmbeddedWebApplicationContext ? 如何强制Spring不加载EmbeddedWebApplicationContext

I have tried to exclude all the AutoConfiguration classes found in org.springframework.boot.autoconfigure.web with the @EnableAutoConfiguration(exclude = ...) annotation. 我试图使用@EnableAutoConfiguration(exclude = ...)注释@EnableAutoConfiguration(exclude = ...) org.springframework.boot.autoconfigure.web所有AutoConfiguration类。

You can use the SpringApplicationBuilder class to explicitly disable loading a web environment and context, ie in your main class: 您可以使用SpringApplicationBuilder类显式禁用加载Web环境和上下文,即在您的主类中:

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

You can try using the @ContextConfiguration annotation: 您可以尝试使用@ContextConfiguration批注:

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

The annotatedClass.class are the class that are annotated , for instance with: @Component , @Service , @Repository . annotatedClass.class是在类注释 ,例如有: @Component@Service@Repository

In this answer this is the suggested approach for testing purposes, but I think it might help you 这个答案中,这是用于测试目的的建议方法,但我认为它可能对您有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 强制Spring Boot不使用EmbeddedWebApplicationContext? - Forcing Spring Boot to NOT use EmbeddedWebApplicationContext? Spring Boot:由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext - Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 春季启动应用程序:ApplicationContextException:无法启动EmbeddedWebApplicationContext - spring-boot application: ApplicationContextException: Unable to start EmbeddedWebApplicationContext 由于缺少 EmbeddedServletContainerFactory bean,Spring Boot 无法启动 EmbeddedWebApplicationContext - Spring Boot Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean Spring boot -- 由于缺少 EmbeddedServletContainerFactory bean 无法启动 EmbeddedWebApplicationContext - Spring boot -- Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean 如何避免我的 spring-boot 与 hibernate 应用程序的查询将被写入控制台或文件? - How can i avoid the queries of my spring-boot with hibernate app will be written to console or file? 我可以轻松地用spring-boot替换spring-boot-starter以避免使用spring-boot-starter-parent吗? - Can I easily replace spring-boot-starter by spring-boot to avoid use of spring-boot-starter-parent? 如何使用 Spring 引导从 POST 方法返回 object? - How can I return an object from a POST method with Spring Boot? 如何从 Spring Boot 中的实体访问存储库? - How can I access the repository from the entity in Spring Boot? 如何在春季启动时从wsdl生成肥皂服务? - How can i generate soap service from wsdl in spring boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM