改变配置文件的获取方式!改成singleton!
This commit is contained in:
		@@ -1,8 +1,9 @@
 | 
			
		||||
{
 | 
			
		||||
    "tns_name": "xmcx1",
 | 
			
		||||
    "ip_addr": "10.39.0.86",
 | 
			
		||||
    "user_name": "",
 | 
			
		||||
    "password": "",
 | 
			
		||||
    "jdbc_url": "",
 | 
			
		||||
    "user_name": "xim_offical_account",
 | 
			
		||||
    "password": "Cpic#1234",
 | 
			
		||||
    "tables": [
 | 
			
		||||
        {
 | 
			
		||||
            "table_name": "",
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,6 @@ import java.util.Vector;
 | 
			
		||||
 | 
			
		||||
public class AppMain
 | 
			
		||||
{
 | 
			
		||||
    private static final String CONFIG_FILE_PATH = "./config.json";
 | 
			
		||||
 | 
			
		||||
    public static void main( String[] args )
 | 
			
		||||
    {
 | 
			
		||||
        String json;
 | 
			
		||||
@@ -30,7 +28,7 @@ public class AppMain
 | 
			
		||||
        // 读取配置
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            config = WeatherDisasterNotifyConfig.load( CONFIG_FILE_PATH );
 | 
			
		||||
            config = WeatherDisasterNotifyConfig.getConfig();
 | 
			
		||||
        }
 | 
			
		||||
        catch (IOException error)
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,11 +11,17 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy;
 | 
			
		||||
public class WeatherDisasterNotifyConfig
 | 
			
		||||
{
 | 
			
		||||
    private static final int BUFFER_SIZE = 1024;
 | 
			
		||||
    private static final String CONFIG_FILE_PATH = "./config.json";
 | 
			
		||||
    private static WeatherDisasterNotifyConfig appConfig = null;
 | 
			
		||||
 | 
			
		||||
    public static WeatherDisasterNotifyConfig load( String filePath ) throws IOException
 | 
			
		||||
    public static WeatherDisasterNotifyConfig getConfig() throws IOException
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
        WeatherDisasterNotifyConfig config = null;
 | 
			
		||||
        if ( appConfig != null)
 | 
			
		||||
        {
 | 
			
		||||
            return appConfig;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ObjectMapper mapper = new ObjectMapper();
 | 
			
		||||
        FileReader configFile = null;
 | 
			
		||||
        StringBuffer json = null;
 | 
			
		||||
@@ -26,7 +32,7 @@ public class WeatherDisasterNotifyConfig
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            configFile = new FileReader( filePath );
 | 
			
		||||
            configFile = new FileReader( CONFIG_FILE_PATH );
 | 
			
		||||
            json = new StringBuffer();
 | 
			
		||||
 | 
			
		||||
            int length = configFile.read( buffer );
 | 
			
		||||
@@ -38,7 +44,7 @@ public class WeatherDisasterNotifyConfig
 | 
			
		||||
                length = configFile.read( buffer );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            config = mapper.readValue( json.toString(), WeatherDisasterNotifyConfig.class );
 | 
			
		||||
            appConfig = mapper.readValue( json.toString(), WeatherDisasterNotifyConfig.class );
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
@@ -55,7 +61,7 @@ public class WeatherDisasterNotifyConfig
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return config;
 | 
			
		||||
        return appConfig;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public WeatherDisasterNotifyConfig()
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 17:33:30
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-23 23:51:46
 | 
			
		||||
 * @LastEditTime: 2022-04-25 21:33:07
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfig.java
 | 
			
		||||
 * @Description: 
 | 
			
		||||
 * 
 | 
			
		||||
@@ -11,7 +11,11 @@
 | 
			
		||||
package com.cpic.xim.config.db;
 | 
			
		||||
 | 
			
		||||
import java.util.Vector;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonProperty;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Description oracle数据库相关参数对象。
 | 
			
		||||
 */
 | 
			
		||||
public class OracleConfig
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@@ -75,10 +79,21 @@ public class OracleConfig
 | 
			
		||||
        this.tables = tables;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "tns_name")
 | 
			
		||||
    private String tnsName;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "ip_addr")
 | 
			
		||||
    private String ipAddr;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "jdbc_url")
 | 
			
		||||
    private String jdbcURL;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "user_name")
 | 
			
		||||
    private String userName;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "password")
 | 
			
		||||
    private String password;
 | 
			
		||||
 | 
			
		||||
    @JsonProperty( "tables")
 | 
			
		||||
    private Vector<DBTable> tables;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,74 @@
 | 
			
		||||
/*
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-25 21:45:12
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-25 22:58:47
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigLoader.java
 | 
			
		||||
 * @Description: oracle数据库配置文件加载类
 | 
			
		||||
 * 
 | 
			
		||||
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
 | 
			
		||||
 */
 | 
			
		||||
package com.cpic.xim.config.db;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.*;
 | 
			
		||||
 | 
			
		||||
public class OracleConfigLoader
 | 
			
		||||
{
 | 
			
		||||
    private static final String CONFIG_FILE_PATH = "./db.json";
 | 
			
		||||
    private static final int BUFFER_SIZE = 1024;
 | 
			
		||||
    private static OracleConfig dbConfig = null;
 | 
			
		||||
 | 
			
		||||
    private OracleConfigLoader()
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    public OracleConfig getOracleConfig() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        FileReader file = null;
 | 
			
		||||
        StringBuffer json = null;
 | 
			
		||||
        char[] buffer = new char[BUFFER_SIZE];
 | 
			
		||||
 | 
			
		||||
        if ( dbConfig != null)
 | 
			
		||||
        {
 | 
			
		||||
            return dbConfig;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            file = new FileReader( CONFIG_FILE_PATH );
 | 
			
		||||
            json = new StringBuffer();
 | 
			
		||||
 | 
			
		||||
            int count = file.read( buffer );
 | 
			
		||||
 | 
			
		||||
            while (count != -1)
 | 
			
		||||
            {
 | 
			
		||||
                json.append( buffer );
 | 
			
		||||
 | 
			
		||||
                count = file.read( buffer );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ObjectMapper mapper = new ObjectMapper();
 | 
			
		||||
 | 
			
		||||
            dbConfig = mapper.readValue( json.toString(), OracleConfig.class );
 | 
			
		||||
        }
 | 
			
		||||
        catch (IOException error)
 | 
			
		||||
        {
 | 
			
		||||
            throw error;
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                file.close();
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception error)
 | 
			
		||||
            {
 | 
			
		||||
                error.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return dbConfig;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 * @Author: Kane
 | 
			
		||||
 * @Date: 2022-04-22 10:53:49
 | 
			
		||||
 * @LastEditors: Kane
 | 
			
		||||
 * @LastEditTime: 2022-04-25 17:40:31
 | 
			
		||||
 * @LastEditTime: 2022-04-25 19:20:32
 | 
			
		||||
 * @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\wechat\officalAccount\sendMessage.java
 | 
			
		||||
 * @Description: 用来推送公众号消息的程序库。
 | 
			
		||||
 *
 | 
			
		||||
@@ -75,6 +75,20 @@ public class sendMessage
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @param warningID
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    private boolean checkWarningHasSended( String warningID )
 | 
			
		||||
    {
 | 
			
		||||
        boolean result = false;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static
 | 
			
		||||
    {
 | 
			
		||||
        // 预警级别色彩
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user