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

Azure Web App容器(Spring Boot 3)与SQL Server混合连接启动故障

概述

我已将Spring Boot API从私有容器注册表部署至Azure容器化Web应用实例,并通过Azure混合中继配置了混合连接,其中混合连接管理器(HCM)部署在可连接Microsoft SQL Server 2014的Windows 2022服务器VM上。

连接字符串:jdbc:sqlserver://<hostname>:<port>;databaseName=<db_name>
混合连接:<hostname>:<port>

部署后,Web应用中的容器运行最终报错:

ERROR - Container didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging.

从输出日志来看,容器卡在HikariPool阶段,无法建立数据库连接:

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.2)

2023-08-31T11:20:16.250-04:00  INFO 14128 --- [           main] Application      : Starting Application using Java 17.0.6 with PID 14128 
2023-08-31T11:20:16.252-04:00  INFO 14128 --- [           main] Application      : The following 1 profile is active: "dev"
2023-08-31T11:20:17.085-04:00  INFO 14128 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-08-31T11:20:17.110-04:00  INFO 14128 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
2023-08-31T11:20:17.656-04:00  INFO 14128 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8000 (http)
2023-08-31T11:20:17.665-04:00  INFO 14128 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-08-31T11:20:17.665-04:00  INFO 14128 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.11]
2023-08-31T11:20:17.739-04:00  INFO 14128 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-08-31T11:20:17.741-04:00  INFO 14128 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1447 ms
2023-08-31T11:20:17.888-04:00  INFO 14128 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...

指标显示,Web应用启动初期,发送端客户端连接失败。

Spring Boot应用配置

Azure部署的激活配置文件使用托管标识,从指定的Azure密钥保管库(spring-cloud-azure-starter-keyvault)中获取数据库凭据。

注意:使用Intellij Azure Tools模拟托管标识进行本地测试时,该配置可正常运行。

server:
  port: 8000

spring:
  cloud:
    azure:
      credential:
        managed-identity-enabled: true
      keyvault:
        secret:
          property-source-enabled: true
          property-sources:
            - endpoint: https://${keyvault}.vault.azure.net/
              retry:
                mode: exponential
                exponential:
                  max-retries: 4
                  base-delay: PT0.0801S
                  max-delay: PT9S
  datasource:
    url: ${db-url}
    username: ${db-user}
    password: ${db-pass}
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

HCM配置

HCM及Azure门户中的所有配置均显示为已连接状态。

容器配置

FROM <java-17-image>

EXPOSE 8000

ENV PROFILE=<default_profile>

WORKDIR /opt/app

COPY ../../target/<application_name>.jar app.jar

ENTRYPOINT [ "java", "-jar", "-Dspring.profiles.active=${PROFILE}", "app.jar"]

注意:未以root用户运行容器(示例中已省略)

已执行的排查步骤

测试托管标识

在本地使用Intellij Azure Tools,以Azure部署的激活配置文件运行应用,配置可正常访问密钥保管库凭据并通过相同连接字符串建立数据库连接。

检查HCM日志

查看运行HCM的Windows 2022 Server VM上的事件查看器,确认HCM无连接问题。

验证Windows VM可访问数据库

确认VM能够访问数据库主机:

Test-NetConnection <host> -Port <port>

在Web App控制台检查TCP连接

确认可从Web应用bash控制台访问混合连接主机:

tcpping <host> <port>

内容的提问来源于stack exchange,提问作者David Rose-Franklin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 17:05:04