com.jfinal.kit.PropKit Java Examples

The following examples show how to use com.jfinal.kit.PropKit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WeixinApiController.java    From jfinal-weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 如果要支持多公众账号,只需要在此返回各个公众号对应的  ApiConfig 对象即可
 * 可以通过在请求 url 中挂参数来动态从数据库中获取 ApiConfig 属性值
 */
public ApiConfig getApiConfig() {
	ApiConfig ac = new ApiConfig();
	
	// 配置微信 API 相关常量
	ac.setToken(PropKit.get("token"));
	ac.setAppId(PropKit.get("appId"));
	ac.setAppSecret(PropKit.get("appSecret"));
	
	/**
	 *  是否对消息进行加密,对应于微信平台的消息加解密方式:
	 *  1:true进行加密且必须配置 encodingAesKey
	 *  2:false采用明文模式,同时也支持混合模式
	 */
	ac.setEncryptMessage(PropKit.getBoolean("encryptMessage", false));
	ac.setEncodingAesKey(PropKit.get("encodingAesKey", "setting it in config file"));
	return ac;
}
 
Example #2
Source File: WeixinMsgController.java    From jfinal-weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 如果要支持多公众账号,只需要在此返回各个公众号对应的  ApiConfig 对象即可
 * 可以通过在请求 url 中挂参数来动态从数据库中获取 ApiConfig 属性值
 */
public ApiConfig getApiConfig() {
	ApiConfig ac = new ApiConfig();
	
	// 配置微信 API 相关常量
	ac.setToken(PropKit.get("token"));
	ac.setAppId(PropKit.get("appId"));
	ac.setAppSecret(PropKit.get("appSecret"));
	
	/**
	 *  是否对消息进行加密,对应于微信平台的消息加解密方式:
	 *  1:true进行加密且必须配置 encodingAesKey
	 *  2:false采用明文模式,同时也支持混合模式
	 */
	ac.setEncryptMessage(PropKit.getBoolean("encryptMessage", false));
	ac.setEncodingAesKey(PropKit.get("encodingAesKey", "setting it in config file"));
	return ac;
}
 
Example #3
Source File: JbootCoreConfig.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 设置必要的系统参数:
 * 有些组件,比如 apollo、sentinel 等配置需要通过 System Properites来进行配置的
 */
private void initSystemProperties() {

    //加载 jboot-system.properties 代替启动参数的 -D 配置
    File spf = new File(PathKit.getRootClassPath(), "jboot-system.properties");
    if (spf.exists() && spf.isFile()) {
        Properties properties = PropKit.use(spf).getProperties();
        if (properties != null && !properties.isEmpty()) {
            for (Object key : properties.keySet()) {
                if (StrUtil.isNotBlank(key)) {
                    String newKey = key.toString().trim();
                    String systemValue = System.getProperty(newKey);
                    if (StrUtil.isNotBlank(systemValue)) {
                        continue;
                    }
                    String newValue = properties.getProperty(newKey);
                    if (StrUtil.isNotBlank(newValue)) {
                        System.setProperty(newKey, newValue.trim());
                    }
                }
            }
        }
    }

    //apollo 配置
    ApolloServerConfig apolloConfig = Jboot.config(ApolloServerConfig.class);
    if (apolloConfig.isEnable() && apolloConfig.isConfigOk()) {
        System.setProperty("app.id", apolloConfig.getAppId());
        System.setProperty("apollo.meta", apolloConfig.getMeta());
    }

}
 
Example #4
Source File: IndexController.java    From zooadmin with MIT License 5 votes vote down vote up
public void dologin() {
    ResultData result = new ResultData();
    String addr = getPara("addr");
    String password = getPara("password");
    String pwd = PropKit.use("user.properties").get("root");
    if (StrKit.isBlank(password) || !password.equals(pwd)) {
        result.setSuccess(false);
        result.setMessage("请输入正确的密码登陆!");
        renderJson(result);
    } else {
        if (StrKit.notBlank(addr)) {
            try {
                ZKPlugin zkPlugin = new ZKPlugin(addr);
                if (getSessionAttr("zk-client") == null) {
                    setSessionAttr("zk-client", zkPlugin.getClient());
                    setSessionAttr("addr", addr);
                }
            } catch (Exception e) {
                log.error("ZKPlugin error.", e);
                result.setSuccess(false);
                result.setMessage("连接到ZooKeeper失败,请复核!");
            }

        } else {
            result.setSuccess(false);
            result.setMessage("ZooKeeper 地址不能为空!");
        }
        renderJson(result);
    }
}
 
Example #5
Source File: XDocJfinalController.java    From xDoc with MIT License 5 votes vote down vote up
public XDocJfinalController() {
    boolean enable = PropKit.getBoolean("xdoc.enable", true);

    if (!enable || apiDoc != null) {
        return;
    }

    synchronized (XDocJfinalController.class) {
        if (apiDoc != null) {
            return;
        }
        init();
    }

}
 
Example #6
Source File: JFinalTestApplication.java    From xDoc with MIT License 5 votes vote down vote up
@Override
public void configConstant(Constants constants) {
    constants.setJsonFactory(new JacksonFactory());
    constants.setDevMode(true);

    PropKit.use("application.txt");
}
 
Example #7
Source File: Test.java    From my_curd with Apache License 2.0 5 votes vote down vote up
static void init() {
    Prop jdbcProp = PropKit.use("config-dev.txt");
    DruidPlugin dp = new DruidPlugin(jdbcProp.get("oa.jdbc.url"),
            jdbcProp.get("oa.jdbc.user"), jdbcProp.get("oa.jdbc.password"), jdbcProp.get("oa.jdbc.driver"));
    dp.start();
    ActiveRecordPlugin arp = new ActiveRecordPlugin(ActivitiConfig.DATASOURCE_NAME, dp);
    arp.setDialect(new MysqlDialect());
    arp.setShowSql(true);
    arp.start();
    ActivitiPlugin ap = new ActivitiPlugin();
    ap.start();
}
 
Example #8
Source File: MysqlDataSourceUtils.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 获得数据库数据源,用于代码生成器
 *
 * @return 数据源
 */
public static DataSource getDataSource() {
    // 根据实际情况配置
    Prop configProp = PropKit.use("jdbc.properties");
    DruidPlugin dp = new DruidPlugin(configProp.get("jdbc.url"), configProp.get("jdbc.user"),
            configProp.get("jdbc.password"), configProp.get("jdbc.driver"));
    dp.start();
    return dp.getDataSource();
}
 
Example #9
Source File: IndexController.java    From zooadmin with MIT License 5 votes vote down vote up
public void dologin() {
    ResultData result = new ResultData();
    String addr = getPara("addr");
    String password = getPara("password");
    String pwd = PropKit.use("user.properties").get("root");
    if (StrKit.isBlank(password) || !password.equals(pwd)) {
        result.setSuccess(false);
        result.setMessage("请输入正确的密码登陆!");
        renderJson(result);
    } else {
        if (StrKit.notBlank(addr)) {
            try {
                ZKPlugin zkPlugin = new ZKPlugin(addr);
                if (getSessionAttr("zk-client") == null) {
                    setSessionAttr("zk-client", zkPlugin.getClient());
                    setSessionAttr("addr", addr);
                }
            } catch (Exception e) {
                log.error("ZKPlugin error.", e);
                result.setSuccess(false);
                result.setMessage("连接到ZooKeeper失败,请复核!");
            }

        } else {
            result.setSuccess(false);
            result.setMessage("ZooKeeper 地址不能为空!");
        }
        renderJson(result);
    }
}
 
Example #10
Source File: InstallUtil.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean createJbootPropertiesFile() {

        File propertieFile = new File(PathKit.getRootClassPath(), "jboot.properties");
        DbExecuter dbExecuter = InstallManager.me().getDbExecuter();

        Properties p = propertieFile.exists()
                ? PropKit.use("jboot.properties").getProperties()
                : new Properties();


        //jboot.app.mode
        putPropertie(p, "jboot.app.mode", "product");

        //cookieEncryptKey
        String cookieEncryptKey = StrUtil.uuid();
        if (putPropertie(p, "jboot.web.cookieEncryptKey", cookieEncryptKey)) {
            Jboot.config(JbootWebConfig.class).setCookieEncryptKey("cookieEncryptKey");
            CookieUtil.initEncryptKey(cookieEncryptKey);
        }

        //jwtSecret
        String jwtSecret = StrUtil.uuid();
        if (putPropertie(p, "jboot.web.jwt.secret", jwtSecret)) {
            Jboot.config(JwtConfig.class).setSecret(jwtSecret);
        }

        p.put("jboot.datasource.type", "mysql");
        p.put("jboot.datasource.url", dbExecuter.getJdbcUrl());
        p.put("jboot.datasource.user", dbExecuter.getDbUser());
        p.put("jboot.datasource.password", StrUtil.obtainDefaultIfBlank(dbExecuter.getDbPassword(), ""));

        return savePropertie(p, propertieFile);
    }
 
Example #11
Source File: JFinalCoreConfig.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
private void initXxlJobExecutor() {

		// registry jobhandler
		XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler());
		XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler());
		XxlJobExecutor.registJobHandler("httpJobHandler", new HttpJobHandler());
		XxlJobExecutor.registJobHandler("commandJobHandler", new CommandJobHandler());

		// load executor prop
		Prop xxlJobProp = PropKit.use("xxl-job-executor.properties");

		// init executor
		xxlJobExecutor = new XxlJobExecutor();
		xxlJobExecutor.setAdminAddresses(xxlJobProp.get("xxl.job.admin.addresses"));
		xxlJobExecutor.setAccessToken(xxlJobProp.get("xxl.job.accessToken"));
		xxlJobExecutor.setAddress(xxlJobProp.get("xxl.job.executor.address"));
		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.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);
		}
	}
 
Example #12
Source File: WeixinConfig.java    From jfinal-weixin with Apache License 2.0 5 votes vote down vote up
/**
 * 如果生产环境配置文件存在,则优先加载该配置,否则加载开发环境配置文件
 * @param pro 生产环境配置文件
 * @param dev 开发环境配置文件
 */
public void loadProp(String pro, String dev) {
	try {
		PropKit.use(pro);
	}
	catch (Exception e) {
		PropKit.use(dev);
	}
}
 
Example #13
Source File: WeixinConfig.java    From jfinal-weixin with Apache License 2.0 5 votes vote down vote up
public void configConstant(Constants me) {
	loadProp("a_little_config_pro.txt", "a_little_config.txt");
	me.setDevMode(PropKit.getBoolean("devMode", false));
	
	// ApiConfigKit 设为开发模式可以在开发阶段输出请求交互的 xml 与 json 数据
	ApiConfigKit.setDevMode(me.getDevMode());
}
 
Example #14
Source File: DemoConfig.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * PropKit.useFirstFound(...) 使用参数中从左到右最先被找到的配置文件
 * 从左到右依次去找配置,找到则立即加载并立即返回,后续配置将被忽略
 */
static void loadConfig() {
	if (p == null) {
		p = PropKit.useFirstFound("demo-config-pro.txt", "demo-config-dev.txt");
	}
}