2017-02-16 16:36:22 +08:00
|
|
|
package cn.cloudowr.dict;
|
|
|
|
|
|
2017-02-20 13:36:55 +08:00
|
|
|
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
2017-11-21 15:57:16 +08:00
|
|
|
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
2017-02-16 16:36:22 +08:00
|
|
|
import com.jfinal.config.*;
|
|
|
|
|
import com.jfinal.template.Engine;
|
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
|
import com.mongodb.MongoCredential;
|
|
|
|
|
import com.mongodb.ServerAddress;
|
|
|
|
|
import com.mongodb.client.MongoDatabase;
|
|
|
|
|
|
2017-11-21 15:57:16 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
2017-02-16 16:36:22 +08:00
|
|
|
import java.util.Arrays;
|
2017-11-21 15:57:16 +08:00
|
|
|
import java.util.Properties;
|
2017-02-16 16:36:22 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by lyf66 on 2017/2/16.
|
|
|
|
|
*/
|
|
|
|
|
public class Config extends com.jfinal.config.JFinalConfig{
|
|
|
|
|
|
|
|
|
|
private static MongoDatabase mongoDatabase;
|
2017-11-21 15:57:16 +08:00
|
|
|
private static String username;
|
|
|
|
|
private static String database;
|
|
|
|
|
private static String password;
|
|
|
|
|
private static String host;
|
|
|
|
|
private static int port;
|
|
|
|
|
private static String dabaseName;
|
2017-02-16 16:36:22 +08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configConstant(Constants me) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configRoute(Routes me) {
|
|
|
|
|
me.add("/", Controller.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configEngine(Engine me) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configPlugin(Plugins me) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configInterceptor(Interceptors me) {
|
2017-02-19 09:51:44 +08:00
|
|
|
me.add(new JQueryParameterFilter());
|
2017-02-20 13:36:55 +08:00
|
|
|
me.add(new ErrorInterceptor());
|
2017-02-16 16:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configHandler(Handlers me) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterJFinalStart() {
|
2017-11-21 15:57:16 +08:00
|
|
|
read();
|
|
|
|
|
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
|
|
|
|
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
|
|
|
|
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
2017-02-16 16:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MongoDatabase getMongoDataBase() {
|
|
|
|
|
return mongoDatabase;
|
|
|
|
|
}
|
2017-11-21 15:57:16 +08:00
|
|
|
public static void read(){
|
|
|
|
|
try{
|
|
|
|
|
Properties pro = new Properties();
|
|
|
|
|
pro.load(Config.class.getResourceAsStream("/config.properties"));
|
|
|
|
|
username = pro.getProperty("username");
|
|
|
|
|
database = pro.getProperty("database");
|
|
|
|
|
password = pro.getProperty("password");
|
|
|
|
|
host = pro.getProperty("host");
|
|
|
|
|
port = Integer.parseInt(pro.getProperty("port"));
|
|
|
|
|
dabaseName = pro.getProperty("dabaseName");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|