繁体   English   中英

如何在 Intellij Idea 中为 Spring Boot 项目构建 jar 文件?

[英]How to build jar file for Spring Boot project in Intellij Idea?

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

应用程序属性

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

application-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 中的开发在此处输入图片说明

出罐在此处输入图片说明

在此处输入图片说明

在 prod 中,您正在运行应用程序而不设置活动配置文件,因此它将仅使用application.properties的设置: 在此处输入图片说明

尝试使用 prod-profile 例如在 prod 中启动您的应用程序

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM