初始化提交
parent
a217fe7dad
commit
cf9207aaae
|
|
@ -9,23 +9,18 @@ import com.mongodb.MongoCredential;
|
|||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
|
||||
import static cn.cloudowr.dict.Main.*;
|
||||
|
||||
/**
|
||||
* Created by lyf66 on 2017/2/16.
|
||||
*/
|
||||
public class Config extends com.jfinal.config.JFinalConfig{
|
||||
|
||||
private static MongoDatabase mongoDatabase;
|
||||
private static String username;
|
||||
private static String database;
|
||||
private static String password;
|
||||
private static String host;
|
||||
private static int port;
|
||||
private static String dabaseName;
|
||||
|
||||
|
||||
@Override
|
||||
public void configConstant(Constants me) {
|
||||
|
|
@ -59,7 +54,6 @@ public class Config extends com.jfinal.config.JFinalConfig{
|
|||
|
||||
@Override
|
||||
public void afterJFinalStart() {
|
||||
read();
|
||||
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
||||
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
||||
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
||||
|
|
@ -68,19 +62,5 @@ public class Config extends com.jfinal.config.JFinalConfig{
|
|||
public static MongoDatabase getMongoDataBase() {
|
||||
return mongoDatabase;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,11 +2,37 @@ package cn.cloudowr.dict;
|
|||
|
||||
import com.jfinal.core.JFinal;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by lyf66 on 2017/2/16.
|
||||
*/
|
||||
public class Main {
|
||||
public static String username;
|
||||
public static String database;
|
||||
public static String password;
|
||||
public static String host;
|
||||
public static int port;
|
||||
public static String dabaseName;
|
||||
private static int AppPort;
|
||||
public static void main(String[] args) {
|
||||
JFinal.start("src/main/webapp", 4200, "/");
|
||||
read();
|
||||
JFinal.start("src/main/webapp", AppPort, "/");
|
||||
}
|
||||
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");
|
||||
AppPort = Integer.parseInt(pro.getProperty("AppPort"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ password=CoWR1111
|
|||
host=120.24.5.249
|
||||
port=3717
|
||||
dabaseName=dict
|
||||
AppPort=4202
|
||||
Loading…
Reference in New Issue