Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated the web app to support profiles, as well.
- Loading branch information
Showing
5 changed files
with
82 additions
and
30 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
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
45 changes: 45 additions & 0 deletions
45
.../main/java/org/cloudfoundry/workers/stocks/web/StockWebApplicationContextInitializer.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,45 @@ | ||
package org.cloudfoundry.workers.stocks.web; | ||
|
||
import org.cloudfoundry.runtime.env.CloudEnvironment; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; | ||
|
||
/** | ||
* this class is called before the DispatcherServlet machinery is created, | ||
* and gives us a chance to influence the {@link org.springframework.context.ApplicationContext} | ||
* profiles. | ||
* | ||
* @author Josh Long | ||
*/ | ||
public class StockWebApplicationContextInitializer implements ApplicationContextInitializer<AnnotationConfigWebApplicationContext> { | ||
|
||
private CloudEnvironment cloudEnvironment = new CloudEnvironment(); | ||
|
||
private boolean isCloudFoundry() { | ||
return cloudEnvironment.isCloudFoundry(); | ||
} | ||
|
||
@Override | ||
public void initialize(AnnotationConfigWebApplicationContext applicationContext) { | ||
|
||
|
||
String profile; | ||
if (isCloudFoundry()) { | ||
profile = "cloud"; | ||
} else { | ||
profile = "local"; | ||
} | ||
|
||
applicationContext.getEnvironment().setActiveProfiles(profile); | ||
|
||
|
||
Class<?>[] configs = {WebMvcConfiguration.class}; | ||
String[] basePkgs = new String[configs.length]; | ||
int i = 0; | ||
for (Class<?> pkg : configs) | ||
basePkgs[i++] = pkg.getPackage().getName(); | ||
|
||
applicationContext.scan(basePkgs); | ||
applicationContext.refresh(); | ||
} | ||
} |
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