Search in sources :

Example 1 with PropertiesProxy

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"));
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) Test(org.junit.Test)

Example 2 with PropertiesProxy

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);
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) IOException(java.io.IOException) UnknownClassException(org.apache.shiro.util.UnknownClassException) ShiroException(org.apache.shiro.ShiroException) ConfigurationException(org.apache.shiro.config.ConfigurationException)

Example 3 with PropertiesProxy

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);
    }
}
Also used : IJobHandler(com.xxl.job.core.handler.IJobHandler) JobHandler(com.xxl.job.core.handler.annotation.JobHandler) IJobHandler(com.xxl.job.core.handler.IJobHandler) PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) XxlJobExecutor(com.xxl.job.core.executor.XxlJobExecutor)

Example 4 with PropertiesProxy

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)));
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) Config(com.ctrip.framework.apollo.Config)

Example 5 with PropertiesProxy

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;
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) InputStream(java.io.InputStream)

Aggregations

PropertiesProxy (org.nutz.ioc.impl.PropertiesProxy)8 InputStream (java.io.InputStream)3 Config (com.ctrip.framework.apollo.Config)1 XxlJobExecutor (com.xxl.job.core.executor.XxlJobExecutor)1 IJobHandler (com.xxl.job.core.handler.IJobHandler)1 JobHandler (com.xxl.job.core.handler.annotation.JobHandler)1 Info (io.swagger.models.Info)1 Swagger (io.swagger.models.Swagger)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ShiroException (org.apache.shiro.ShiroException)1 ConfigurationException (org.apache.shiro.config.ConfigurationException)1 UnknownClassException (org.apache.shiro.util.UnknownClassException)1 Test (org.junit.Test)1