|
|
|
@ -30,6 +30,7 @@ import com.dsideal.QingLong.Zjcq.Controller.ZjcqController;
|
|
|
|
|
import com.jfinal.config.*;
|
|
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
@ -50,18 +51,12 @@ public class Start extends JFinalConfig {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void configConstant(Constants me) {
|
|
|
|
|
//使用LogBack
|
|
|
|
|
me.setLogFactory(new LogBackLogFactory());
|
|
|
|
|
|
|
|
|
|
// //读取程序运行的目录
|
|
|
|
|
// PropKit.clear();
|
|
|
|
|
// PropKit.use("undertow.properties");
|
|
|
|
|
// CommonUtil.WebRoot = PropKit.get("undertow.resourcePath").split(",")[0];
|
|
|
|
|
// PropKit.clear();
|
|
|
|
|
|
|
|
|
|
// 加载少量必要配置,随后可用PropKit.get(...)获取值
|
|
|
|
|
PropKit.clear();
|
|
|
|
|
PropKit.use("undertow.properties");
|
|
|
|
|
CommonUtil.WebRoot = PropKit.get("undertow.resourcePath").split(",")[0];
|
|
|
|
|
PropKit.clear();
|
|
|
|
|
PropKit.use("application.properties");
|
|
|
|
|
//配置统一的错误页面
|
|
|
|
|
me.setError404View("/html/common/404/index.html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,36 +127,51 @@ public class Start extends JFinalConfig {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configPlugin(Plugins me) {
|
|
|
|
|
HikariCpPlugin hpPlugin = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
|
|
|
|
|
PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
|
|
|
|
hpPlugin.setConnectionTestQuery(connectionTestQuery);
|
|
|
|
|
hpPlugin.setConnectionTimeout(connectionTimeoutMs);
|
|
|
|
|
hpPlugin.setIdleTimeout(idleTimeoutMs);
|
|
|
|
|
hpPlugin.setMaxLifetime(maxLifetimeMs);
|
|
|
|
|
hpPlugin.setMaximumPoolSize(maxPoolSize);
|
|
|
|
|
me.add(hpPlugin);
|
|
|
|
|
|
|
|
|
|
// 配置ActiveRecord插件
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(hpPlugin);
|
|
|
|
|
arp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
|
|
|
|
|
//遍历sql目录下所有的sql文件
|
|
|
|
|
File sqlDir;
|
|
|
|
|
String basePath = PathKit.getRootClassPath();
|
|
|
|
|
sqlDir = new File(basePath + "/Sql");
|
|
|
|
|
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
|
|
|
|
masterPlugin.setConnectionTestQuery(this.connectionTestQuery);
|
|
|
|
|
masterPlugin.setConnectionTimeout(this.connectionTimeoutMs);
|
|
|
|
|
masterPlugin.setIdleTimeout(this.idleTimeoutMs);
|
|
|
|
|
masterPlugin.setMaxLifetime(this.maxLifetimeMs);
|
|
|
|
|
masterPlugin.setMaximumPoolSize(this.maxPoolSize);
|
|
|
|
|
String jdbcUrlSlave = PropKit.get("jdbcUrlSlave");
|
|
|
|
|
if (StrKit.isBlank(jdbcUrlSlave)) {
|
|
|
|
|
jdbcUrlSlave = PropKit.get("jdbcUrl");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HikariCpPlugin slavePlugin = new HikariCpPlugin(jdbcUrlSlave, PropKit.get("user"), PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
|
|
|
|
slavePlugin.setConnectionTestQuery(this.connectionTestQuery);
|
|
|
|
|
slavePlugin.setConnectionTimeout(this.connectionTimeoutMs);
|
|
|
|
|
slavePlugin.setIdleTimeout(this.idleTimeoutMs);
|
|
|
|
|
slavePlugin.setMaxLifetime(this.maxLifetimeMs);
|
|
|
|
|
slavePlugin.setMaximumPoolSize(this.maxPoolSize);
|
|
|
|
|
me.add(masterPlugin);
|
|
|
|
|
me.add(slavePlugin);
|
|
|
|
|
ActiveRecordPlugin masterArp = new ActiveRecordPlugin("master", masterPlugin);
|
|
|
|
|
masterArp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
|
|
|
|
|
slaveArp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
String basePath = Start.class.getClassLoader().getResource(".").getPath();
|
|
|
|
|
File sqlDir = new File(basePath + "/Sql");
|
|
|
|
|
File[] sqlFiles = sqlDir.listFiles();
|
|
|
|
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
|
|
|
|
//只加载.sql文件
|
|
|
|
|
File[] var10 = sqlFiles != null ? sqlFiles : new File[0];
|
|
|
|
|
int var11 = var10.length;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < var11; ++i) {
|
|
|
|
|
File sqlFile = var10[i];
|
|
|
|
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
|
|
|
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//加载
|
|
|
|
|
me.add(arp);
|
|
|
|
|
// 用于缓存模块的redis服务
|
|
|
|
|
RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10 * 1000);
|
|
|
|
|
//启动redis组件
|
|
|
|
|
|
|
|
|
|
me.add(masterArp);
|
|
|
|
|
me.add(slaveArp);
|
|
|
|
|
RedisPlugin redis = new RedisPlugin("Redis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10000);
|
|
|
|
|
me.add(redis);
|
|
|
|
|
if (!StrKit.isBlank(PropKit.get("pika_ip")) && !StrKit.isBlank(PropKit.get("pika_port"))) {
|
|
|
|
|
RedisPlugin pika = new RedisPlugin("Pika", PropKit.get("pika_ip"), PropKit.getInt("pika_port"), 10000);
|
|
|
|
|
me.add(pika);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|