不管什么原因,A项目服务就是引用了jar spring-boot-starter-web:
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
所以项目一启动,就会去找 server.port 端口了。
找到,使用,占用。
如果我们没配置 server.port 也会默认去找8080 。
不给这个 A 项目 服务 占用 端口。
因为这个不是一个web服务(比如是一个dubbo接口服务等)。
总而言之,就是不想给这个服务用web端口。
第一种
在配置文件加上:
- spring:
- main:
- allow-bean-definition-overriding: true
- web-application-type: none
第二种
在启动类设置 setWebApplicationType
- public static void main(String[] args) {
- new SpringApplicationBuilder(Application .class)
- .web(WebApplicationType.NONE)
- .run(args);
- }
或
- public static void main(String[] args) {
- try {
- SpringApplication app = new SpringApplication(JCtestyApplication.class);
- app.setWebApplicationType(WebApplicationType.NONE);
- app.setBannerMode(Banner.Mode.CONSOLE);
- app.setBanner(new ResourceBanner(new ClassPathResource("config/banner.txt")));
- app.run(args);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
如: