【问题标题】:How to build jar file for Spring Boot project in Intellij Idea?如何在 Intellij Idea 中为 Spring Boot 项目构建 jar 文件?
【发布时间】:2021-11-13 14:23:47
【问题描述】:

我有三个 *.properties 文件。当我在工作室中的这些文件之间切换时,一切都按预期工作。但是当我构建一个 jar 文件时,我认为它找不到属性文件,它在端口 8080 上可见。虽然在设置中我指定了 8090(开发)或 5000(产品)。如何解决这个问题呢。谁能告诉我如何正确组装 jar 文件?

application.properties

spring.profiles.active=prod

应用程序-dev.properties

# ---- Server ----
server.port=8090
server.error.include-stacktrace=never
# ---- Mail ----
spring.mail.username=************@gmail.com
spring.mail.password=************
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
# ---- Postgres ----
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database=POSTGRESQL
spring.datasource.url=jdbc:postgresql://localhost:5432/endpoint
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.properties.hibernate.id.new_generator_mappings=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
# ---- Firebase ----
app.firebase.config=serviceAccountKey.json

应用程序-prod.properties

# ---- Server ----
server.port=5000
server.error.include-stacktrace=never
# ---- Mail ----
spring.mail.username=************@gmail.com
spring.mail.password=************
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
# ---- Postgres ----
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database=POSTGRESQL
spring.datasource.url=jdbc:postgresql://localhost:5432/endpoint
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.properties.hibernate.id.new_generator_mappings=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
# ---- Firebase ----
app.firebase.config=serviceAccountKey.json

在 Intellij 中生产

在 Intellij 中的开发

外罐

【问题讨论】:

  • 你是如何构建 jar 的?您是否在 gradle 构建文件中定义了 Spring Boot 插件。
  • 是的,我有:插件 { id 'org.springframework.boot' 版本 '2.5.6' id 'io.spring.dependency-management' 版本 '1.0.11.RELEASE' id 'java ' } Build jar: File -> Project Structure -> Artifacts -> Add ->Jar/From modules and dependencies... -> 接下来,我选择 ,指定
    并选择 ,因为如果我选择 并在资源中指定 META-INF/MANIFEST.MF,当使用控制台运行 jar 时,我没有得到清单类
  • 请不要将代码添加为 cmets,因为这完全不可读。而是编辑您的问题。

标签: java spring-boot spring-data-jpa


【解决方案1】:

在 prod 中,您正在运行应用程序而没有设置活动配置文件,因此它将仅使用来自 application.properties 的设置:

尝试使用 prod 配置文件在 prod 中启动您的应用程序,例如

java -jar -Dspring.profiles.active=prod application.jar

【讨论】:

    猜你喜欢
    • 2017-06-03
    • 2016-09-03
    • 2018-03-01
    • 2016-11-30
    • 2015-12-27
    • 2020-08-28
    • 2014-07-12
    • 2017-11-03
    • 2023-01-28
    相关资源
    最近更新 更多