How to prevent auto start of tomcat/jetty in Spring Boot when I only want to use RestTemplate

前端 未结 3 2057
时光取名叫无心
时光取名叫无心 2021-02-05 05:57

I want to use RestTemplate/TestRestTemplate by including the artifact in a SpringBoot application

    
        org.springframewo         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 06:50

    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).

    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-application-type=none
    

    Or you can use the SpringApplicationBuilder

    new SpringApplicationBuilder(YourApp.class)
            .web(WebApplicationType.NONE).run(args);
    

提交回复
热议问题