增加配置文件
parent
59a8241dcf
commit
a217fe7dad
4
pom.xml
4
pom.xml
|
|
@ -84,7 +84,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.cloudowr</groupId>
|
<groupId>cn.cloudowr</groupId>
|
||||||
<artifactId>sdk</artifactId>
|
<artifactId>sdk</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.4.16</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${basedir}/lib/sdk-1.4.16.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
package cn.cloudowr.dict;
|
package cn.cloudowr.dict;
|
||||||
|
|
||||||
import cn.cloudowr.sdk.JQueryParameterFilter;
|
|
||||||
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
||||||
import cn.cloudowr.sdk.jfinal.ErrorRender;
|
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
||||||
import com.jfinal.aop.Interceptor;
|
|
||||||
import com.jfinal.aop.Invocation;
|
|
||||||
import com.jfinal.config.*;
|
import com.jfinal.config.*;
|
||||||
import com.jfinal.core.ActionException;
|
|
||||||
import com.jfinal.render.Render;
|
|
||||||
import com.jfinal.template.Engine;
|
import com.jfinal.template.Engine;
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.MongoCredential;
|
import com.mongodb.MongoCredential;
|
||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by lyf66 on 2017/2/16.
|
* Created by lyf66 on 2017/2/16.
|
||||||
|
|
@ -22,6 +20,12 @@ import java.util.Arrays;
|
||||||
public class Config extends com.jfinal.config.JFinalConfig{
|
public class Config extends com.jfinal.config.JFinalConfig{
|
||||||
|
|
||||||
private static MongoDatabase mongoDatabase;
|
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
|
@Override
|
||||||
public void configConstant(Constants me) {
|
public void configConstant(Constants me) {
|
||||||
|
|
@ -55,12 +59,28 @@ public class Config extends com.jfinal.config.JFinalConfig{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterJFinalStart() {
|
public void afterJFinalStart() {
|
||||||
MongoCredential mongoCredential = MongoCredential.createCredential("root", "admin", "CoWR1111".toCharArray());
|
read();
|
||||||
MongoClient mongoClient = new MongoClient(new ServerAddress("120.24.5.249", 3717), Arrays.asList(mongoCredential));
|
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
||||||
mongoDatabase = mongoClient.getDatabase("dict");
|
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
||||||
|
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MongoDatabase getMongoDataBase() {
|
public static MongoDatabase getMongoDataBase() {
|
||||||
return mongoDatabase;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
username=root
|
||||||
|
database=admin
|
||||||
|
password=CoWR1111
|
||||||
|
host=120.24.5.249
|
||||||
|
port=3717
|
||||||
|
dabaseName=dict
|
||||||
Loading…
Reference in New Issue