在微服务开发时,有时候某个服务可能并不需要是一个web项目,这时候应该怎么做呢?
- 去除pom中的
web-starter
替换spring-boot-starter-web为spring-boot-starter,如果其他pom引入了web则需要逐一排除<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency> - 配置文件指定为非Web应用
spring:main:web-application-type: none - 启动方法指定非Web应用
new SpringApplicationBuilder(XXX.class).web(WebApplicationType.NONE).run(args);