当我只想使用RestTemplate时,如何防止在Spring Boot中自动启动tomcat / jetty [英] How to prevent auto start of tomcat/jetty in Spring Boot when I only want to use RestTemplate
问题描述
我想通过在SpringBoot应用程序中包含工件来使用RestTemplate / TestRestTemplate
I want to use RestTemplate/TestRestTemplate by including the artifact in a SpringBoot application
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
但这会自动启动Tomcat或Jetty。有没有办法将其关闭,或者不包括上述工件。 TestRestTemplate在引导工件中,但不在基础RestTemplate中。
But this automatically starts Tomcat or Jetty. Is there a way to turn it off, or by not including the above artifact. TestRestTemplate is in the boot artifact, but not the base RestTemplate.
推荐答案
Spring Boot不会启动Web容器,如果它是不存在。 spring-web
不提供任何嵌入式容器。您可能想要分析项目的依赖关系(尝试 mvn依赖关系:树
)。
Spring Boot is not going to start a web container if it's not present. spring-web
does not provide any embedded container. You may want to analyse the dependencies of your project (try mvn dependency:tree
).
如果你想要确保您的Spring启动应用程序中没有启动Web服务器,您可以设置以下配置键
If you want to make sure a web server is not started in your spring boot application, you can set the following configuration key
spring.main.web-environment=false
或者你可以使用 SpringApplicationBuilder
new SpringApplicationBuilder(YourApp.class)
.web(false).run(args);
这篇关于当我只想使用RestTemplate时,如何防止在Spring Boot中自动启动tomcat / jetty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!