关注分享主机优惠活动
国内外VPS云服务器

org . c source . common . my exception:item " tracker _ serv

异常已解决。本人写的博客项目,使用工具类初始化配置进行测试。代码如下:使用加载配置文件生成相应的输入流,使用对象加载输入流工具类初始化配置进行测试。代码如下。

org . c source . common . my exception:null未找到异常中的项目“tracker _ server”已解决。本人写的博客项目,用java工具class A用fastDfs初始化fdfs配置进行了测试,代码如下

class path resource CPR = new class path resource(" fastdfs . properties ");client global . init(CPR . getclass loader()。getResource("fdfs_client.conf ")。旅游()。getPath());Properties属性=新属性();//使用ClassLoader加载属性配置文件生成对应的输入流inputstream in = CPR . getinputstream();//使用properties对象加载输入流properties . load(in);ClientGlobal.initByProperties(属性);tracker group tracker group = client global . g _ tracker _ group;tracker client = new tracker client(tracker group);b类初始化fdfs配置进行测试,代码如下

私有静态最终字符串CONF _文件名=线程.当前线程()。getContextClassLoader()。getResource("fdfs_client.conf ")。getPath();-------------------------------------------------client global . init(CONF _文件名);这两种方法都用于读取配置文件fdfs_client.conf,但它在本地工作,而不是在服务器上(CentOS7.6)。错误内容如下:java.io.file处的Java . lang . nullpointerexception .(file . Java:277)org . csource . common . inifile reader . loadfromsfilesystemorclasspathasstream(inifile reader . Java:45)org . csource . common . inifile reader . Java:150)org . csource . common . inifile reader .(inifile reader . Java:30)org . csource . fast DFS . client global . init(init 在org . Apache . Shiro . web . servlet . onceperrequestfilter . do filter(onceperrequestfilter . Java:125)在org . Apache . catalina . core . applicationfilter chain . internal dolfilter(applicationfilter chain . Java:189)在org . Apache . catalina . core . applicationfilter chain . do filter(applicationfilter chain . Java:162)在org . spring framework . web . filter . requestcontext filter . dofilter internal(requestcontext filter . Java:100)在org . spring 711[http -nio -8000-exec -1]ERROR com . blog . utils . fastdfsclientutils -org . c source . common . my exception:item " tracker _ server " in null not found 2021-11-24 21:13:42.712 INFO 249 8+--[nio -8000-exec -1]com . blog . controller . fastdfscontroller:--4 不读取配置文件,而是将fdfs的配置直接写入工具类,以加载代码,如下所示

Properties props = new Properties();props.put(ClientGlobal。PROP_KEY_TRACKER_SERVERS," 82 . 157 . 172 . 63:22122 ");props.put(ClientGlobal。PROP _ KEY _ CONNECT _ time out _ IN _ SECONDS,3);props.put(ClientGlobal。PROP _ KEY _ NETWORK _ time out _ IN _ SECONDS,30);client global . initbyproperties(props);tracker client tracker client = new tracker client();完成工具类代码公共类fastdfsclientils { private static logger logger = logger . get logger(fastdfsclientils . class);私有静态跟踪客户端跟踪客户端;//加载文件static { try {//Load fasetdfs配置项Properties props = new Properties();props.put(ClientGlobal。PROP_KEY_TRACKER_SERVERS," 82 . 157 . 172 . 63:22122 ");props.put(ClientGlobal。PROP _ KEY _ CONNECT _ time out _ IN _ SECONDS,3);props.put(ClientGlobal。PROP _ KEY _ NETWORK _ time out _ IN _ SECONDS,30);client global . initbyproperties(props);tracker client = new tracker client();///*第二个init方法。我可以在本地测试这个方法,但不能在服务器上测试。如果使用自测//class path resource CPR = new class path resource(" fastdfs . properties ");//client global . init(CPR . getclass loader()。getResource("fdfs_client.conf ")。旅游()。getPath());////Properties Properties = new Properties();////使用ClassLoader加载属性配置文件生成对应的输入流//inputstream in = CPR . getinputstream();////使用properties对象//properties.load(in)加载输入流;//client global . initbyproperties(属性);////tracker group tracker group = client global . g _ tracker _ group;//tracker client = new tracker client(tracker group);////system . out . println(" ------> "+tracker client . gettrackerserver()。getInetSocketAddress());} catch(Exception e){ logger . error(e);}}/* * *方法名称:上传方法*摘要描述:* @ param file file * @ param path path * @ return上传成功时返回id,上传失败时返回null */public static string Upload(file file,string path){ Tracker Server Tracker Server = null;storage server storage server = null;StorageClient1存储客户端= nullFileInputStream fis = nulltry { name value pair[]meta _ list = null;//新的name value pair[0];fis = new FileInputStream(文件);byte[]file _ buff = null;如果(fis!= null){ int len = fis . available();file_buff =新字节[len];fis . read(file _ buff);} tracker server = tracker client . gettrackerserver();if(tracker server = = null){ logger . error(" getConnection return null ");} storage server = tracker client . getstorestoration(tracker server);storageClient1 =新的StorageClient1(trackerServer,storage server);string fileid = storage client 1 . upload _ file 1(file _ buff,getFileExt(path),meta _ list);返回fileid} catch(Exception ex){ logger . error(ex);返回null}最后{if (fis!= null){ try { fis . close();} catch(io exception e){ logger . error(e);} } storageClient1 = null}}/* * *方法名:上传方法*摘要描述:* @ param data data * @ param extName path * @ return上传时成功返回id,失败时返回null */public static string Upload(byte[]data,string extName){ Tracker Server Tracker Server = null;storage server storage server = null;StorageClient1存储客户端= nulltry { name value pair[]meta _ list = null;//新的name value pair[0];tracker server = tracker client . gettrackerserver();if(tracker server = = null){ logger . error(" getConnection return null ");} storage server = tracker client . getstorestoration(tracker server);storageClient1 =新的StorageClient1(trackerServer,storage server);string fileid = storage client 1 . upload _ file 1(data,extName,meta _ list);返回fileid} catch(Exception ex){ logger . error(ex);返回null} finally { storageClient1 = null}}/* * *方法名:Download Method *摘要描述:Download by File id * @ param fileId File id * @ returns InputStream */public static InputStream Download(string group Name,string fileId){ Tracker Server Tracker Server = null;storage server storage server = null;StorageClient1存储客户端= null请尝试{ tracker server = tracker client . gettrackerserver();if(tracker server = = null){ logger . error(" getConnection return null ");} storage server = tracker client . getstorestoration(tracker server,group name);storageClient1 =新的StorageClient1(trackerServer,storage server);byte[]bytes = storage client 1 . download _ file 1(fileId);InputStream InputStream = new bytearray InputStream(字节);返回inputStream} catch(Exception ex){ logger . error(ex);返回null} finally { storageClient1 = null}}/* * *方法名称:Delete Method *摘要描述:根据文件id删除文件* @param fileId文件id * @return。如果删除成功,操作失败,错误码*/public static int delete(string group name,string fileid){ tracker server tracker server = null;storage server storage server = null;StorageClient1存储客户端= null请尝试{ tracker server = tracker client . gettrackerserver();if(tracker server = = null){ logger . error(" getConnection return null ");} storage server = tracker client . getstorestoration(tracker server,group name);storageClient1 =新的StorageClient1(trackerServer,storage server);int result = storage client 1 . delete _ file 1(fileId);返回结果;} catch(Exception ex){ logger . error(ex);返回0;} finally { storageClient1 = null}}/* * *方法名:*摘要描述:* @param oldFileId旧文件id * @param file新文件* @param path新文件路径* @ret

未经允许不得转载:主机频道 » org . c source . common . my exception:item " tracker _ serv

相关推荐

评论 抢沙发

评论前必须登录!