有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

占位符Spring Boot中的java映射

在必须使用注入占位符的情况下,如何将默认映射类型值传递给配置类:

foo:
  bar:
    mappedVariable: ${INJECTIBLE_MAP:{desired:'mapHere'}}

我一直在犯这样的错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'foo.bar.mappedVariable' to java.util.Map<java.lang.String, java.lang.String>:

    Reason: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]

Action:

Update your application's configuration


Process finished with exit code 0

我也尝试过引用值,结果似乎是一样的:

foo:
  bar:
    mappedVariable: ${INJECTIBLE_MAP:${foo.bar.initalValues}}
    initialValues:
    ...

将配置类中的变量名更改为initialValues效果很好,但我需要有注入的可能性


共 (0) 个答案