solution: read configuration from dshackle.yaml (in current directory)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
build/
|
build/
|
||||||
out/
|
out/
|
||||||
*.iml
|
*.iml
|
||||||
|
*.yaml
|
||||||
@@ -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"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user