【发布时间】: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
【问题讨论】:
-
你是如何构建 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