【问题标题】:Active profile ignored活动配置文件被忽略
【发布时间】:2019-12-20 09:43:58
【问题描述】:

Sample code

我已经在 application.properties 文件中添加了“spring.profiles.active=local” 但是在运行应用程序时,它无法识别配置文件并使用默认配置文件运行

application.properties

# Tomcat Server Config
server.port=8071

#Profile Config
spring.profiles.active=local

application-local.properties

# Spring JPA Config
spring.datasource.url=jdbc:postgresql://localhost:5432/User
spring.datasource.username=postgres
spring.datasource.password=amt123`

# Hibernate Config
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto=none

【问题讨论】:

  • 您的application.properties 文件在哪里?
  • 欢迎来到 SO。请不要将您的代码发布为场外图像。请将您的代码和(错误)消息粘贴到您的问题中。您可以使用格式正确地格式化您的代码。有关如何提问的更多信息,请参阅stackoverflow.com/help/how-to-ask。有关格式化的更多信息,请参阅stackoverflow.com/editing-help
  • 当我使用“java -jar”命令运行 jar 文件时,它正在使用指定的配置文件运行,但是当我使用 IDE 运行时,它无法检测到配置文件并回退到默认配置文件跨度>
  • @cassiomolin 它位于 src/main/resources

标签: spring-boot intellij-idea


【解决方案1】:

"spring.devtools.add-properties" 默认值为true 一旦设置为 false,spring boot 将禁用配置文件配置。 对我来说,即使我将值设置为 true,仍然没有启用配置文件配置

我通过删除 dev-tool 依赖项并再次添加它来解决此问题。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-devtools</artifactId>
   <scope>runtime</scope>
</dependency>

我不确定内部工作流程。 如果有人对此有适当的解释,请发表评论

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 2022-10-25
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    相关资源
    最近更新 更多