【问题标题】:-Dspring.profiles.active not recognized under condition-Dspring.profiles.active 在条件下无法识别
【发布时间】:2018-11-23 08:31:04
【问题描述】:

我已将-Dspring.profiles.active 作为系统属性传递:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>#{'dev' or 'sit' or 'qa'.equals('${spring.profiles.active}')  ? 'classpath:process${spring.profiles.active}.properties' : 'classpath:env/cfg/process-${spring.profiles.active}.properties'}
      </value>
    </list>
  </property>
</bean>

如果我在 spring.profiles.active 中通过 dev,则条件应该通过,但实际上失败了。

但它已成功更新为 Properties,名为 process-dev.properties

有人能指出我缺少什么吗?

【问题讨论】:

  • 为什么你已经使用 XML 配置而不是 Java 注释的配置?

标签: java spring spring-boot spring-el system-properties


【解决方案1】:

你应该把它改成'dev'.equals('${spring.profiles.active}') or 'sit'.equals('${spring.profiles.active}') or 'qa'.equals('${spring.profiles.active}')

【讨论】:

  • 'dev'.equals('${spring.profiles.active} - 值没有得到
  • 值未更新。 'dev'.equals('${spring.profiles.active}')。它返回假。但我正在传递 -Dspring.profiles.active=dev。它必须返回 true
  • 你能告诉我们确切地你在终端@Anto上输入了什么吗?
  • 我在参数和 application.properties 中传递了 -Dspring.profiles.active=dev。我必须根据 environment 设置这些值。 #{'dev' =='${spring.profiles.active}' ? 'classpath:process${spring.profiles.active}.properties':'classpath:env/process-${spring.profiles.active}.properties'}。使用属性文件名成功更新值,但条件失败,因为条件级别值未通过(#{('${spring.profiles.active}'=='dev')?)
  • 我想要您准确输入的文本。例如java -jar anto.jar -Dspring.profiles.active=dev。只需在此处编写整个命令即可。
猜你喜欢
  • 2020-08-02
  • 2021-12-01
  • 2014-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-13
  • 1970-01-01
  • 2018-08-20
相关资源
最近更新 更多