Play框架加载配置项type OBJECT rather than问题

前言

在使用play框架,通过

Play.application().configuration().getString

获取配置项信息时,运行报错不能注入。
Caused by: org.springframework.beans.factory.BeanCreationException:Could not autowire field

错误信息

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [XXX]: Constructor threw exception; nested exception is Configuration error: Configuration error[reference.conf: 242-244: play.test.url has type OBJECT rather than STRING]

原因

检查了配置项的,发现有些配置项存在类似,但少一级的情况,如:

配置文件:

play.test.url=“url”
play.test.url.test1=“1”
play.test.url.test2=“2”
play.test.url.test3=“3”

程序引用:

    protected final String url1 = Play.application().configuration().getString("play.test.url");
    protected final String url2 = Play.application().configuration().getString("play.test.url.test1");
    protected final String url3 = Play.application().configuration().getString("play.test.url.test2");
    protected final String url4 = Play.application().configuration().getString("play.test.url.test3");

系统取"play.test.url" 的值时,连着后面跟的.testn都算进去了,所以成了个对象,相应的就报错:
has type OBJECT rather than STRING

注意

配置项的名称唯一,且不能存在有类似父子级关系的配置名称

发布了42 篇原创文章 · 获赞 0 · 访问量 1424

猜你喜欢

转载自blog.csdn.net/tcctcszhanghao/article/details/103667363