在Spring Boot应用中,只要在pom.xml中引入了依赖: spring-boot-starter-web, 应用默认就会当成一个Web项目,但有时候我们其实只是想使用 Web 客户端的功能,如: RestTemplate。

在这种情况下,如何阻止Web服务的启动呢?可以在 application.yml 文件中简单的设置应用类型为 NONE, 如:

1
2
3
spring:
main:
web-application-type: NONE

实际上, web-application-type 的类型可以设置为: NONE, REACTIVE, SERVLET 中的一种。

完整的 Spring Boot 设置项文档

TAGS