Java 如何避免Spring引导加载EmbeddedWebApplicationContext?

Java 如何避免Spring引导加载EmbeddedWebApplicationContext?,java,spring,spring-mvc,apache-camel,spring-boot,Java,Spring,Spring Mvc,Apache Camel,Spring Boot,我有一个带有Camel-HTTP的Spring-Boot集成应用程序。由于Camel-HTTP依赖于geronimo-servletSpring-Boot正在尝试加载web应用程序上下文 如何强制Spring不加载嵌入的WebApplicationContext 我已尝试使用@EnableAutoConfiguration(exclude=…)注释排除在org.springframework.boot.autoconfigure.web中找到的所有自动配置类。您可以尝试使用@ContextCon

我有一个带有Camel-HTTP的Spring-Boot集成应用程序。由于Camel-HTTP依赖于
geronimo-servlet
Spring-Boot正在尝试加载web应用程序上下文

如何强制Spring不加载嵌入的WebApplicationContext


我已尝试使用
@EnableAutoConfiguration(exclude=…)
注释排除在
org.springframework.boot.autoconfigure.web中找到的所有自动配置类。

您可以尝试使用
@ContextConfiguration
注释:

@ContextConfiguration(loader = SpringApplicationCtxtLoader.class, classes = annotatedClass.class)
annotatedClass.class
是一个类,例如带有:
@Component
@Service
@Repository

作为回答,这是用于测试目的的建议方法,但我认为它可能会帮助您

您可以使用该类显式禁用加载web环境和上下文, i、 e.在你的主课上:

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

这可能适用于测试,但不适用于Spring启动应用程序本身!我对
SpringApplication
而不是
SprintApplicationBuilder
做了同样的操作,但是它检测servlet并创建web上下文。与建设者它的作品很好。感谢如果javax.servlet.servlet或org.springframework.web.context.ConfigurableWebApplicationContext位于类路径中,则此操作将不起作用。最好调用contextClass方法来指定AnnotationConfigApplicationContext。@ConstantinoCronember
web(false)
调用在
initialize(sources)
方法之后,该方法作为SAB/SA构造函数的一部分被调用,所以不应该是这种情况?在我的例子中,webEnvironment被“web环境”覆盖属性在application.yml类中。在我的例子中,我确实有一个web应用程序,但我想创建另一个入口点,以便能够在不启动Tomcat的情况下运行代码的特定部分。