forked from l0rd/spring-mvc-helloworld
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from marcellodesales/feature/spring-config-clie…
…nt-and-spring-framework-integration-no-springboot Feature/spring config client and spring framework integration no springboot
- Loading branch information
Showing
10 changed files
with
231 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.classpath | ||
.project | ||
.settings | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.zenika.controller; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "github") | ||
public class GithubProperties { | ||
|
||
/** | ||
* Oauth token used for authenticating with GitHub | ||
*/ | ||
private String token; | ||
/** | ||
* Root dir path to clone the repos | ||
*/ | ||
private String cloneBaseDir; | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(String token) { | ||
this.token = token; | ||
} | ||
|
||
public String getCloneBaseDir() { | ||
return cloneBaseDir; | ||
} | ||
|
||
public void setCloneBaseDir(String cloneDir) { | ||
this.cloneBaseDir = cloneDir; | ||
} | ||
|
||
@PostConstruct | ||
public void loadedProperties() { | ||
System.out.println("Github Properties are " + token + " with " + cloneBaseDir); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.zenika.controller; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MyPropeties { | ||
|
||
/** | ||
* Oauth token used for authenticating with GitHub | ||
*/ | ||
@Value("${github.token}") | ||
private String token; | ||
/** | ||
* Root dir path to clone the repos | ||
*/ | ||
@Value("${github.cloneBaseDir}") | ||
private String cloneBaseDir; | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(String token) { | ||
this.token = token; | ||
} | ||
|
||
public String getCloneBaseDir() { | ||
return cloneBaseDir; | ||
} | ||
|
||
public void setCloneBaseDir(String cloneDir) { | ||
this.cloneBaseDir = cloneDir; | ||
} | ||
|
||
@PostConstruct | ||
public void loadedProperties() { | ||
System.out.println("My Properties are: " + token + " with " + cloneBaseDir); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/zenika/controller/config/CloudEnvironment.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.zenika.controller.config; | ||
|
||
import org.springframework.cloud.config.client.ConfigClientProperties; | ||
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.env.MutablePropertySources; | ||
import org.springframework.core.env.PropertySource; | ||
import org.springframework.web.context.support.StandardServletEnvironment; | ||
|
||
public class CloudEnvironment extends StandardServletEnvironment { | ||
|
||
@Override | ||
protected void customizePropertySources(MutablePropertySources propertySources) { | ||
super.customizePropertySources(propertySources); | ||
try { | ||
PropertySource<?> source = initConfigServicePropertySourceLocator(this); | ||
propertySources.addLast(source); | ||
|
||
} catch ( | ||
|
||
Exception ex) { | ||
logger.warn("failed to initialize cloud config environment", ex); | ||
} | ||
} | ||
|
||
private PropertySource<?> initConfigServicePropertySourceLocator(Environment environment) { | ||
|
||
ConfigClientProperties configClientProperties = new ConfigClientProperties(environment); | ||
configClientProperties.setUri("http://localhost:8888"); | ||
configClientProperties.setName("publisher"); | ||
configClientProperties.setLabel("master"); | ||
|
||
System.out.println("##################### will load the client configuration"); | ||
System.out.println(configClientProperties); | ||
|
||
ConfigServicePropertySourceLocator configServicePropertySourceLocator = | ||
new ConfigServicePropertySourceLocator(configClientProperties); | ||
|
||
return configServicePropertySourceLocator.locate(environment); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/zenika/controller/config/PropertiesConfigurer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.zenika.controller.config; | ||
|
||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; | ||
|
||
import com.zenika.controller.GithubProperties; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties({GithubProperties.class}) | ||
public class PropertiesConfigurer { | ||
|
||
@Bean | ||
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { | ||
return new PropertySourcesPlaceholderConfigurer(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/zenika/controller/config/SpringCloudConfigContext.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.zenika.controller.config; | ||
|
||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.web.context.support.XmlWebApplicationContext; | ||
|
||
public class SpringCloudConfigContext extends XmlWebApplicationContext { | ||
@Override | ||
protected ConfigurableEnvironment createEnvironment() { | ||
System.out.println("##################### loaded my comfigurable context"); | ||
return new CloudEnvironment(); | ||
} | ||
} |
This file contains 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
This file contains 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