[英]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.