solution: read configuration from dshackle.yaml (in current directory)

This commit is contained in:
Igor Artamonov
2019-06-20 16:39:15 -04:00
parent 42c98b5e4c
commit 72c983c68f
5 changed files with 36 additions and 2 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
.gradle/ .gradle/
build/ build/
out/ out/
*.iml *.iml
*.yaml

View File

@@ -64,6 +64,7 @@ dependencies {
compile 'io.projectreactor.addons:reactor-extra:3.2.3.RELEASE' compile 'io.projectreactor.addons:reactor-extra:3.2.3.RELEASE'
compile 'io.projectreactor.kotlin:reactor-kotlin-extensions:1.0.0.M1' compile 'io.projectreactor.kotlin:reactor-kotlin-extensions:1.0.0.M1'
compile 'org.yaml:snakeyaml:1.24'
compile "io.infinitape:etherjar-domain:$etherjarVersion" compile "io.infinitape:etherjar-domain:$etherjarVersion"
compile "io.infinitape:etherjar-hex:$etherjarVersion" compile "io.infinitape:etherjar-hex:$etherjarVersion"

View File

@@ -1,10 +1,14 @@
package io.emeraldpay.dshackle package io.emeraldpay.dshackle
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean
import org.springframework.boot.SpringApplication import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.env.YamlPropertySourceLoader
import org.springframework.context.annotation.Import import org.springframework.context.annotation.Import
import org.springframework.context.annotation.PropertySource
@SpringBootApplication(scanBasePackages = [ "io.emeraldpay.dshackle" ]) @SpringBootApplication(scanBasePackages = [ "io.emeraldpay.dshackle" ])
@PropertySource("file:./dshackle.yaml", ignoreResourceNotFound = true, factory = YamlPropertySourceFactory::class)
@Import(Config::class) @Import(Config::class)
open class Starter open class Starter

View File

@@ -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()
}
}

View File

@@ -1 +1 @@
port=9001 port=9001