
com.glassdoor.planout4j.demos.UsingConfigBackendWithSpring Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of planout4j-demos Show documentation
Show all versions of planout4j-demos Show documentation
PlanOut for Java runnable demos
The newest version!
package com.glassdoor.planout4j.demos;
import java.nio.file.Paths;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.glassdoor.planout4j.Namespace;
import com.glassdoor.planout4j.NamespaceFactory;
import com.glassdoor.planout4j.config.ConfFileLoader;
import com.glassdoor.planout4j.spring.Planout4jAppContext;
/**
* Planout4J with SpringFramework demo.
* Run using mvn exec:java -Dexec.mainClass=com.glassdoor.planout4j.demos.UsingConfigBackendWithSpring [-Dexec.args=unit_value]
*/
public class UsingConfigBackendWithSpring {
@Autowired
private NamespaceFactory namespaceFactory;
public void run(String unit) {
Optional ns = namespaceFactory.getNamespace("demo_namespace", ImmutableMap.of("user_guid", unit));
if (ns.isPresent()) {
// get all params at once
Map allParams = ns.get().getParams();
// get params individually using defaults
int pageSize = ns.get().getParam("page_size", 15);
boolean showFullDetails = ns.get().getParam("full_details", false);
System.out.println("allParams: " + allParams);
System.out.println("pageSize: " + pageSize);
System.out.println("showFullDetails: " + showFullDetails);
}
}
public static void main(String[] args) {
System.setProperty(ConfFileLoader.P4J_CONF_FILE, Paths.get("conf", "demo_planout4j.conf").toString());
new AnnotationConfigApplicationContext(AppCtx.class).getBean(UsingConfigBackendWithSpring.class)
.run(args.length > 0 ? args[0] : "");
System.exit(0);
}
/**
* Dummy "application-specific" context; @Import
is the important part.
*/
@Configuration
@Import(Planout4jAppContext.class)
public static class AppCtx {
@Bean
public UsingConfigBackendWithSpring getUsingConfigBackendWithSpring() {
return new UsingConfigBackendWithSpring();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy