solution: read configuration from dshackle.yaml (in current directory)
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package io.emeraldpay.dshackle
|
||||
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.env.YamlPropertySourceLoader
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.context.annotation.PropertySource
|
||||
|
||||
@SpringBootApplication(scanBasePackages = [ "io.emeraldpay.dshackle" ])
|
||||
@PropertySource("file:./dshackle.yaml", ignoreResourceNotFound = true, factory = YamlPropertySourceFactory::class)
|
||||
@Import(Config::class)
|
||||
open class Starter
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.emeraldpay.dshackle
|
||||
|
||||
import org.apache.commons.lang3.StringUtils
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean
|
||||
import org.springframework.core.env.PropertiesPropertySource
|
||||
import org.springframework.core.env.PropertySource
|
||||
import org.springframework.core.io.Resource
|
||||
import org.springframework.core.io.support.EncodedResource
|
||||
import org.springframework.core.io.support.PropertySourceFactory
|
||||
import java.util.*
|
||||
|
||||
class YamlPropertySourceFactory: PropertySourceFactory {
|
||||
|
||||
override fun createPropertySource(name: String?, resource: EncodedResource): PropertySource<*> {
|
||||
val loadedProperties = this.loadYamlIntoProperties(resource.resource)
|
||||
|
||||
return PropertiesPropertySource(if (StringUtils.isNotBlank(name)) name else resource.resource.filename, loadedProperties)
|
||||
|
||||
}
|
||||
|
||||
private fun loadYamlIntoProperties(resource: Resource): Properties {
|
||||
val factory = YamlPropertiesFactoryBean()
|
||||
factory.setResources(resource)
|
||||
factory.afterPropertiesSet()
|
||||
|
||||
return factory.getObject()
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
port=9001
|
||||
port=9001
|
||||
Reference in New Issue
Block a user