我有三个*.properties文件。当我在studio中的这些文件之间切换时,一切都正常工作。但是当我构建一个jar文件时,我认为它找不到属性文件,它在端口8080上是可见的。尽管在设置中我指定了8090 (开发)或5000 (生产)。如何解决这个问题。有人能告诉我如何正确组装jar文件吗?
application.properties
spring.profiles.active=prod
application-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中的开发
Out jar
发布于 2021-11-14 06:50:19
在prod中,您在没有设置活动配置文件的情况下运行应用程序,因此它将仅使用application.properties
中的设置:
尝试使用prod-profile在prod中启动应用程序
java -jar -Dspring.profiles.active=prod application.jar
https://stackoverflow.com/questions/69955154
复制相似问题