solution: read configuration from dshackle.yaml (in current directory)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
*.iml
|
||||
*.iml
|
||||
*.yaml
|
||||
@@ -64,6 +64,7 @@ dependencies {
|
||||
compile 'io.projectreactor.addons:reactor-extra:3.2.3.RELEASE'
|
||||
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-hex:$etherjarVersion"
|
||||
|
||||
@@ -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