Search in sources :

Example 6 with PropertiesProxy

use of org.nutz.ioc.impl.PropertiesProxy in project nutzboot by nutzam.

the class YamlConfigureLoader method init.

public void init() throws Exception {
    String path = envHolder.get("nutz.boot.configure.properties_path", "application.yml");
    try (InputStream ins = resourceLoader.get(path)) {
        if (ins == null) {
            throw new RuntimeException("yaml not found : " + path);
        }
        conf = new PropertiesProxy();
        readYaml(ins);
    }
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) InputStream(java.io.InputStream)

Example 7 with PropertiesProxy

use of org.nutz.ioc.impl.PropertiesProxy in project nutzboot by nutzam.

the class PropertiesConfigureLoader method init.

public void init() throws Exception {
    // 首先, 确定一些从什么路径加载配置文件,默认值application.properties
    String path = envHolder.get("nutz.boot.configure.properties_path", "application.properties");
    // 另外,加载custom目录下的配置文件,与nutzcn一致
    conf.setPaths("custom/");
    // 加载application.properties
    try (InputStream ins = resourceLoader.get(path)) {
        if (ins != null) {
            conf.load(Streams.utf8r(ins), false);
        }
    }
    // 也许命令行里面指定了profile,需要提前load进来
    PropertiesProxy tmp = new PropertiesProxy();
    if (args != null) {
        parseCommandLineArgs(tmp, args);
        if (tmp.has("nutz.profiles.active")) {
            conf.put("nutz.profiles.active", tmp.remove("nutz.profiles.active"));
        }
    }
    if (allowCommandLineProperties) {
        conf.putAll(System.getProperties());
    }
    // 加载指定profile,如果有的话
    if (conf.has("nutz.profiles.active")) {
        String profile = conf.get("nutz.profiles.active");
        path = path.substring(0, path.lastIndexOf('.')) + "-" + profile + ".properties";
        try (InputStream ins = resourceLoader.get(path)) {
            if (ins != null) {
                conf.load(Streams.utf8r(ins), false);
            }
        }
    }
    // 把命令行参数放进去
    if (tmp.size() > 0) {
        conf.putAll(tmp.toMap());
    }
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) InputStream(java.io.InputStream)

Example 8 with PropertiesProxy

use of org.nutz.ioc.impl.PropertiesProxy in project nutzboot by nutzam.

the class SwaggerServletStarter method init.

public void init(ServletConfig config) throws ServletException {
    PropertiesProxy conf = appContext.getConfigureLoader().get();
    swagger = conf.makeDeep(Swagger.class, "swagger.conf.");
    Info info = conf.makeDeep(Info.class, "swagger.info.");
    swagger.setInfo(info);
    HashSet<Class<?>> classes = new HashSet<>();
    String pkgName = conf.get("swagger.resource.package", appContext.getPackage());
    for (Class<?> klass : Scans.me().scanPackage(pkgName)) {
        classes.add(klass);
    }
    Reader.read(swagger, classes);
}
Also used : PropertiesProxy(org.nutz.ioc.impl.PropertiesProxy) Swagger(io.swagger.models.Swagger) Info(io.swagger.models.Info) HashSet(java.util.HashSet)

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