spring-data-jpa Spring Boot 配置文件未选取属性文件

rseugnpd  于 2022-11-10  发布在  Spring
关注(0)|答案(4)|浏览(153)

我有application-database.ymlapplication-sql.yml。尝试使用-Dspring.profiles.active=local运行,但属性数据没有拾取。如何运行?
application-local.yml

spring:
  profiles:
    group:
      local: database, sql, message
  application: 
    name: HP-FETCHER-CONFIG-SERVICE
xmq68pz9

xmq68pz91#

通过Dspring.profiles.active=local,您告诉Spring您使用的是local配置文件,请改用Dspring.profiles.active=database

csga3l58

csga3l582#

我不确定这是否适用于您的项目:
只需使用application.yml,然后:

spring:                                                                                                                                                                                                
  profiles:                                                                     
    active: local, database, sql

---                                                                                                                
spring:                                                                                                            
  profiles: local1
  ...
...

---                                                                                                                
spring:                                                                                                            
  profiles: local
  ...
...

---                                                                                                                
spring:                                                                                                            
  profiles: sql
  ...
...

---                                                                                                                
spring:                                                                                                            
  profiles: database
  ...
...

如果启动时没有-Dspring.profiles.active,则将使用local, database, sql。如果启动时使用-Dspring.profiles.active=local1,database,sql,则将使用local1, database, sql

p8h8hvxi

p8h8hvxi3#

如果你想使用group,你必须在application.ymlapplication.properties文件中指定它。对应的blog post表示:

  • 若要定义群组,您可以使用spring.profiles.groupapplication.properties或application.yml档案中的www.example.com属性。*
vojdkbi0

vojdkbi04#

对我来说,这似乎是工作的预期。我有下面的application.yml文件

spring:
  profiles:
    group:
      super-1-2: profile-1, profile-2
      super-2-3: profile-2, profile-3

---
spring:
  config:
    activate:
      on-profile:
      - profile-1

---
spring:
  config:
    activate:
      on-profile:
      - profile-2

---
spring:
  config:
    activate:
      on-profile:
      - profile-3

如果我在配置文件super-1-2激活的情况下运行应用程序,我会在日志中得到一个确认,即所有三个super-1-2profile-1profile-2都处于活动状态。

2022-08-31 16:52:27.109  INFO 67935 --- [  restartedMain] c.s.n.SampleApplication      : The following 3 profiles are active: "super-1-2", "profile-1", "profile-2"

另一方面,如果我在配置文件super-2-3激活的情况下运行应用程序,我会在日志中得到一个确认,即所有三个super-2-3profile-2profile-3都是活动的。

2022-08-31 16:52:41.117  INFO 68090 --- [  restartedMain] c.s.n.SampleApplication      : The following 3 profiles are active: "super-2-3", "profile-2", "profile-3"

相关问题