You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring应用未绑定配置端口7777,API无法访问问题求助

Spring Boot应用启动后未监听指定端口排查问题

若此问题更适合Super User板块请见谅,这可能是Windows 11的特性问题?也有可能是Spring配置错误,若选错了Stack Exchange板块请包涵,我仍在学习中!

已做的前置排除:

  • 拔掉笔记本网线并关闭WiFi,排除ISP干扰
  • 运行Application类后等待10分钟,确认PID对应的java.exe进程持续运行

应用配置

application.properties 文件位于src/main/resources,内容如下:

server.port=7777
server.address=localhost

通过org.springframework.core.env.Environment.getProperty("server.port")获取到端口值为7777,与配置一致。

问题现象与已执行排查操作

所有API客户端无法访问该API,已执行以下排查步骤:

  1. 启动前执行命令 netstat -ano | findstr :7777,无返回结果,确认端口未被占用
  2. 启动应用后再次执行上述命令,仍无结果,说明没有应用在监听7777端口
  3. 为7777端口添加Windows 11自带防火墙的入站和出站允许规则
  4. 执行telnet localhost 7777,返回:Connecting To localhost...Could not open connection to the host, on port 7777: Connect failed

应用启动日志

2023-05-29T21:36:23.458+01:00  INFO 13036 --- [           main] 
net.todko.api.Application                : Starting Application 
using Java 19 with PID 13036 
(C:\Storage\Projects\LoadTeacherProto\LoadTeacher\target\classes 
started by ajnyv in 
C:\Storage\Projects\LoadTeacherProto\LoadTeacher)

2023-05-29T21:36:23.467+01:00  INFO 13036 --- [           main] 
net.todko.api.Application                : No active profile set, 
falling back to 1 default profile: "default"

2023-05-29T21:36:24.623+01:00  INFO 13036 --- [           main] 
net.todko.api.Application                : Started Application in 
1.869 seconds (process running for 2.533)
Application is running on port: 7777
Application is running on address: localhost

相关代码文件

Application类

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

@SpringBootApplication
@EnableAsync
public class Application implements ApplicationRunner {

    @Autowired
    private Environment environment;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        Utils.wait(600000);
    }

    @Override
    public void run(ApplicationArguments args) {
        printCurrentPort();
    }


    public void printCurrentPort() {
        String port = environment.getProperty("server.port");
        String address = environment.getProperty("server.address");
        System.out.println("Application is running on port: " + port);
        System.out.println("Application is running on address: " + address);
    }
}

异步配置类

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class ConcurrentConfiguration {

    @Bean(name = "taskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(500);
        executor.setThreadNamePrefix("ApiThread-");
        executor.initialize();
        return executor;
    }
}

若需要BasicController类和Utils.wait()代码,可补充提供。恳请帮忙排查问题!


内容的提问来源于stack exchange,提问作者DraxDomax

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 12:28:15