Skip to content
欢迎扫码关注公众号

Circular placeholder reference

今天准备把两个配置项修改为支持环境变量,所以在配置文件中添加了如下配置:

yaml
ce-shi:
  domain: ${ceshi.domain:liujiajia.me}
  apikey: ${ceshi.apikey:g46e4u8tqyj4u0jvutm05odd7xyn8lus}

结果服务启动报错了,说是绑定异常。

java
org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'ceshi.apikey' to java.lang.String

仔细查看后面的日志才发现真正的原因:占位符循环引用了。

java
Caused by: java.lang.IllegalArgumentException: Circular placeholder reference 'ceshi.apikey:g46e4u8tqyj4u0jvutm05odd7xyn8lus' in property definitions

也就是说配置文件中 ce-shi.apikeySpEL 中的占位符 ceshi.apikey 重复了,导致了循环引用。
可以看出 Spring 在匹配时优先匹配的是配置文件中的配置项,而且匹配时去除了特殊符号,之后在配置文件中找不到对应项时,才会在环境变量中匹配。

解决办法很简单,将占位符修改为不一样的就可以了。

yaml
ce-shi:
  domain: ${cs.domain:liujiajia.me}
  apikey: ${cs.apikey:g46e4u8tqyj4u0jvutm05odd7xyn8lus}

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.