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

启用App Insights后Azure App Service部署Java/容器返回404求助

解决方案:Azure App Service启用App Insights后Spring Boot路由失效的问题
  • 替换无代码Agent为官方标准Agent

    1. 下载对应版本的官方applicationinsights-agent.jar,将其上传至Azure App Service的文件系统(可通过Kudu工具或部署时打包进项目根目录)
    2. 修改App Service的环境变量JAVA_TOOL_OPTS,将原有自动注入的-javaagent:/agent/java/applicationinsights-agent-codeless.jar替换为指向你上传的标准Agent路径,例如:
      -javaagent:/home/site/wwwroot/applicationinsights-agent.jar
      
    3. 添加环境变量APPLICATIONINSIGHTS_CONNECTION_STRING,设置你的Application Insights连接字符串
    4. 重启App Service,验证应用HTTP路由和追踪数据是否正常
  • 改用Spring Starter依赖替代Java Agent

    1. 在Spring Boot项目的构建文件中添加Application Insights Spring Starter依赖:
      • Maven(pom.xml):
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-spring-boot-starter</artifactId>
            <version>3.4.14</version> <!-- 选择与Spring Boot兼容的版本 -->
        </dependency>
        
      • Gradle(build.gradle):
        implementation 'com.microsoft.azure:applicationinsights-spring-boot-starter:3.4.14'
        
    2. 在项目的application.properties或application.yml中配置连接字符串:
      azure.application-insights.connection-string=你的连接字符串
      
    3. 关闭Azure App Service的App Insights自动配置功能(在App Service控制台的「监视」>「Application Insights」中选择禁用自动配置)
    4. 重新构建Jar包并部署,此时无需依赖Java Agent参数,避免路由冲突
  • 排查官方Agent的兼容性问题

    1. 确认下载的applicationinsights-agent版本与你的Spring Boot版本兼容:Spring Boot 3.x需使用Agent 3.4.0及以上版本,Spring Boot 2.x选择对应兼容版本
    2. 通过Azure App Service的「日志流」查看详细错误信息,根据报错调整配置或Agent版本
    3. 先在本地环境用标准Agent启动应用,验证功能正常后再部署到Azure
  • 应急临时方案
    若需快速恢复应用可用性,可暂时关闭App Insights功能,验证应用路由是否正常,确认问题根源后再逐步重新配置追踪功能

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 20:55:19