use of org.nutz.ioc.impl.PropertiesProxy in project nutzboot by nutzam.
the class PropertiesConfigureLoaderTest method test_from_args.
@Test
public void test_from_args() {
PropertiesConfigureLoader configureLoader = new PropertiesConfigureLoader();
configureLoader.parseCommandLineArgs(configureLoader.get(), "--debug --jetty.port=8181 --jetty.host 127.0.0.2 --nutz.profiles.active=test".split(" "));
PropertiesProxy conf = configureLoader.get();
System.out.println(conf.toMap());
assertEquals(4, conf.size());
assertEquals("true", conf.get("debug"));
assertEquals(8181, conf.getInt("jetty.port"));
assertEquals("127.0.0.2", conf.get("jetty.host"));
}
use of org.nutz.ioc.impl.PropertiesProxy in project nutzboot by nutzam.
the class NbShiroEnvironmentLoaderListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
PropertiesProxy conf = appContext.getConfigureLoader().get();
try {
// 走原生API的shiro.ini文件吗?
String iniPath = conf.get("shiro.ini.path", "shiro.ini");
if (conf.has("shiro.ini.path") || appContext.getResourceLoader().has(iniPath)) {
sce.getServletContext().setAttribute(EnvironmentLoader.CONFIG_LOCATIONS_PARAM, iniPath);
super.contextInitialized(sce);
return;
}
} catch (Exception e) {
throw Lang.wrapThrow(e);
}
sce.getServletContext().setAttribute(ENVIRONMENT_CLASS_PARAM, NbResourceBasedWebEnvironment.class.getName());
super.contextInitialized(sce);
}
use of org.nutz.ioc.impl.PropertiesProxy in project xxl-job by xuxueli.
the class NutzSetup method init.
@Override
public void init(NutConfig cfg) {
// regist JobHandler
String[] beanNames = cfg.getIoc().getNamesByType(IJobHandler.class);
if (beanNames == null || beanNames.length == 0) {
return;
}
for (String beanName : beanNames) {
IJobHandler jobHandler = cfg.getIoc().get(IJobHandler.class, beanName);
String name = jobHandler.getClass().getAnnotation(JobHandler.class).value();
XxlJobExecutor.registJobHandler(name, jobHandler);
}
// load executor prop
PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties");
// init executor
xxlJobExecutor = new XxlJobExecutor();
xxlJobExecutor.setAdminAddresses(xxlJobProp.get("xxl.job.admin.addresses"));
xxlJobExecutor.setAppName(xxlJobProp.get("xxl.job.executor.appname"));
xxlJobExecutor.setIp(xxlJobProp.get("xxl.job.executor.ip"));
xxlJobExecutor.setPort(xxlJobProp.getInt("xxl.job.executor.port"));
xxlJobExecutor.setAccessToken(xxlJobProp.get("xxl.job.accessToken"));
xxlJobExecutor.setLogPath(xxlJobProp.get("xxl.job.executor.logpath"));
xxlJobExecutor.setLogRetentionDays(xxlJobProp.getInt("xxl.job.executor.logretentiondays"));
// start executor
try {
xxlJobExecutor.start();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
use of org.nutz.ioc.impl.PropertiesProxy in project nutzboot by nutzam.
the class ApolloConfigureLoader method init.
public void init() throws Exception {
Config config = ConfigService.getAppConfig();
conf = new PropertiesProxy();
config.getPropertyNames().forEach((key) -> conf.put(key, config.getProperty(key, null)));
}
use of org.nutz.ioc.impl.PropertiesProxy in project nutz by nutzam.
the class NutMvcListener method findConfig.
/**
* 首先,载入需要的配置信息, 分别从nutz.properties和ServletContext的上下文获取.
* <p/>
* 子类可以覆盖这个方法实现从任意方式加载配置
*/
protected void findConfig() {
String propLocation = sc.getInitParameter(PROP_LOCATION);
if (Strings.isBlank(propLocation)) {
propLocation = "nutz.properties";
}
PropertiesProxy pp = new PropertiesProxy();
Enumeration<String> params = sc.getInitParameterNames();
while (params.hasMoreElements()) {
String name = (String) params.nextElement();
if (name.startsWith("nutz-")) {
pp.put(name, sc.getInitParameter(name).trim());
}
}
// 先找找classpath
InputStream in = getClass().getClassLoader().getResourceAsStream("/" + propLocation);
if (in == null) {
in = sc.getResourceAsStream("/WEB-INF/" + propLocation);
}
if (in == null) {
log.debug(propLocation + " not found");
} else {
pp = new PropertiesProxy(in);
Streams.safeClose(in);
}
this.pp = pp;
}
Aggregations