# How to read a property from a config?

  1. Reading a project-level config property

    1. define the property in lottery/conf/Smile.conf file. For example:

      search.url="www.google.com"
      
    2. to read the property:

      • import com.iteration3.Smile

      • Use Smile.conf.getString() api to read the property

        import com.iteration3.Smile
        val searchUrl:Option[String] = Smile.conf.getString("search.url")
        
      • By default, Smile.conf.get api's return an option but if you are sure the property would be defined, prefix with Must as follows

        val searchUrl:String = Smile.conf.getStringMust("search.url")
        

        For more details Types of config properties?

  2. Reading a module-level config property

    1. define the property the respective module's conf. For example, to access a property only inside LotteryDomain module, define it in lottery/modules/lottery/LotteryDomain/conf/lotterydomain.conf file.

    2. to read the property, use module DomainObject.conf as shown below:

      val bucketName = LotteryDomainObject.conf.getString("s3.bucket.name")
      

REFERENCES