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

Spring应用在IntelliJ正常运行,打包成JAR后启动失败求助

问题分析与解决方案

你的应用在IDEA中运行正常但JAR启动失败,核心是两个独立问题:InfluxDB配置未生效、SSL健康指示器依赖缺失,以下是针对性解决办法:

1. InfluxDB 使用默认数据库 mydb 而非配置的 TSA_MOCK

报错显示尝试创建mydb,说明你的InfluxDB配置未被正确加载,大概率是Spring Boot版本与配置属性前缀不匹配:

  • 若你的项目使用Spring Boot 3.x,Micrometer Influx的配置前缀已从management.influx.metrics.export改为management.metrics.export.influx,需修正配置:
    # Micrometer InfluxDB (适配Spring Boot 3.x)
    management.metrics.export.influx.api-version=v1
    management.metrics.export.influx.uri=http://ltmonitor:8086
    management.metrics.export.influx.user-name=user
    management.metrics.export.influx.password=user
    management.metrics.export.influx.db=TSA_MOCK
    

旧前缀在Spring Boot 3.x中已被废弃,会导致配置失效,框架自动使用默认值mydb。

2. SslBundles Bean 缺失导致启动失败

这是因为Spring Boot Actuator自动启用了SslHealthIndicator,但你的应用未配置SSL相关内容,也未引入对应依赖,解决二选一:

  • 方案一:直接禁用SSL健康指示器(推荐,若不需要SSL监控)
    在application.properties中添加:
    management.health.ssl.enabled=false
    
  • 方案二:添加SSL Starter依赖(若需SSL相关功能)
    Maven(pom.xml):
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-ssl</artifactId>
    </dependency>
    
    Gradle(build.gradle):
    implementation 'org.springframework.boot:spring-boot-starter-ssl'
    

后续验证

  1. 修正配置后,重新执行打包操作
  2. 启动JAR时可通过--spring.config.name=application或直接使用默认配置路径,确保配置文件被正确加载

内容的提问来源于stack exchange,提问作者Михаил Воробьев

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 12:17:43