Incerteza
Incerteza

Reputation: 34944

Defining an array in play's config file

I didn't find any information about that topic. Is there any way to define an array in the standard play config file app.config which have such the values as?

application.secret="Gk<9kCgMu@A62eyfcJ;YZ2nFnA;4324/gfdg]afdsfds"
application.langs="en"
application.global=common.Global

Upvotes: 2

Views: 3296

Answers (2)

Simonluca Landi
Simonluca Landi

Reputation: 921

I find this answer searching for "play framework config array".

For Play 2.7 the correct syntax for a List is:

my.setting=["value1","value2","value3"]

otherwise you get an Exception like

com.typesafe.config.ConfigException$WrongType: application.conf @ file:/xxxxx/application.conf: 12:  my.setting has type STRING rather than LIST

Hope this helps someone else.

Upvotes: 0

serejja
serejja

Reputation: 23881

Yes, it is possible and described in the Play configuration chapter.

In general, what you are looking for is this:

my.setting="[value1,value2,value3]"

In your code you can access it like this:

Play.current.configuration.getStringList("my.setting") //returns an Option[java.util.List[String]]

You may also use getLongList, getBooleanList and so on.

Upvotes: 5

Related Questions