/** 配置插件 */ public void configPlugin(Plugins me) { // [ copy from @ mike 的适配器 :) ] String dbname, username, password, host, port, driver; driver = getProperty("driverClass"); if (isLocal) { dbname = getProperty("dbname"); username = getProperty("username"); port = getProperty("port"); host = getProperty("host"); password = getProperty("password"); } else { JSONObject credentials = JSONObject.parseObject(json) .getJSONArray("mysql-5.1") .getJSONObject(0) .getJSONObject("credentials"); host = credentials.getString("host"); port = credentials.getString("port"); dbname = credentials.getString("name"); username = credentials.getString("username"); password = credentials.getString("password"); } DruidPlugin druidPlugin = new DruidPlugin( "jdbc:mysql://" + host + ":" + port + "/" + dbname, username, password, driver); druidPlugin.setInitialSize(3).setMaxActive(10); me.add(druidPlugin); // 配置ActiveRecord插件 ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin); if (isLocal) { arp.setShowSql(true); } arp.addMapping("module", Module.class) .addMapping("topic", Topic.class) .addMapping("post", Post.class); arp.addMapping("reply", Reply.class).addMapping("sub_module", SubModule.class); me.add(arp); // 缓存插件 me.add(new EhCachePlugin()); }