首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Intellij Idea中为Spring Boot项目构建jar文件?

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

Stack Overflow用户
提问于 2021-11-13 14:23:48
回答 1查看 175关注 0票数 0

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

application.properties

代码语言:javascript
运行
复制
spring.profiles.active=prod

application-dev.properties

代码语言:javascript
运行
复制
# ---- 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

代码语言:javascript
运行
复制
# ---- 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中的开发

Out jar

EN

回答 1

Stack Overflow用户

发布于 2021-11-14 06:50:19

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

尝试使用prod-profile在prod中启动应用程序

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69955154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档