Last active
December 17, 2015 14:19
-
-
Save danveloper/5623263 to your computer and use it in GitHub Desktop.
Groovy Configuration DSL for environment properties in Spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.danveloper.reactor.config | |
reactor { | |
social { | |
twitter { | |
consumerKey = "ABCD" | |
consumerSecret = "EFGH" | |
accessToken = "IJKL" | |
accessTokenSecret = "MNOP" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
class SpringConfiguration { | |
@Bean | |
public static PropertyPlaceholderConfigurer props() { | |
def config = new ConfigSlurper().parse(ApplicationConfiguration) | |
def configurer = new PropertyPlaceholderConfigurer() | |
configurer.setProperties(config.toProperties()) | |
configurer | |
} | |
@Bean | |
public TemplateFactory templateFactory() { | |
new TemplateFactory() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class TemplateFactory { | |
@Value('${reactor.social.twitter.consumerKey}') | |
private String consumerKey | |
@Value('${reactor.social.twitter.consumerSecret}') | |
private String consumerSecret | |
@Value('${reactor.social.twitter.accessToken}') | |
private String accessToken | |
@Value('${reactor.social.twitter.accessTokenSecret}') | |
private String accessTokenSecret | |
TwitterTemplate createTwitterTemplate() { | |
new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment